【发布时间】:2017-10-10 04:19:42
【问题描述】:
当我们的 WordPress 安装同时发送大量电子邮件时,其中一些会被丢弃。由于我们将退订链接附加到每封电子邮件的底部,因此每封电子邮件都必须单独发送。有一个 wp_mail 过滤器,如下所示。
如果我们只发送少量电子邮件,它们通常会毫无问题地发送,但当发送 100 封或更多电子邮件时,问题会变得更加明显。在最后的 105 封电子邮件中,总共发送了 94 封,然后是 96 封,看起来随机的消失了,如果我们让循环在发送电子邮件之间等待一段时间,它们都会被发送。这是一个解决方案,但我们想知道是什么问题,希望能够解决它并允许电子邮件以系统允许的最快速度发送。
add_filter('wp_mail', 'wp_mail_filter', 10, 1);
function wp_mail_filter( $args ) {
$to = $args['to'];
// Multiple recipients resend as individual emails
if (is_array($to)) {
foreach($to as $recipient)
wp_mail( $recipient, $args['subject'], $args['message'], $args['headers'], $args['attachments']);
} else {
$message = 'Custom message based on user associated with address';
$new_wp_mail = array(
'to' => $to,
'subject' => $args['subject'],
'message' => $message,
'headers' => $args['headers'],
'attachments' => $args['attachments'],
);
return $new_wp_mail;
}
// Arrive here from multiple mails, send blank
return array('to' => '', 'subject' => '', 'message' => '');
}
【问题讨论】:
-
电子邮件发送服务器会拒绝您的电子邮件,如果它们来得太快。你不能用它做任何事情。
标签: wordpress