所以我有以下代码:
while(list($i, $data_subscriber) = each($subscriber)) {
$email_counter = $i + 1;
echo ($email_counter).') '.$data_subscriber->field_1.' '.$data_subscriber->field_2.' - '.$data_subscriber->email.''."\n";
flush();
$language = $data_subscriber->lang;
$body_mail = include($template_send_newsletter);
$first_name_idx = $data_subscriber->field_1;
$last_name_idx = $data_subscriber->field_2;
if (mail_send(strtolower($data_subscriber->email),
( IsSet($first_name_idx) && IsSet($last_name_idx) ? $first_name_idx.' '.$last_name_idx : $data_subscriber->email ),
$site_admin,
$site_name,
'Newsletter ['.date('d/m/Y', time()).']',
true,
$body_mail,
NULL,
false)) {
reset($data_subscriber->newsletter_item);
unset($log_detail);
$log_detail = "";
while(list($j, $list_of_news_to_send) = each($data_subscriber->newsletter_item)) {
$log_detail = ( IsSet($list_of_news_to_send->title) ? $list_of_news_to_send->title."\n" : '');
$log_detail = ( IsSet($list_of_news_to_send->subtitle) ? $list_of_news_to_send->subtitle."\n" : '');
$log_detail = ( IsSet($list_of_news_to_send->creation_date) ? $list_of_news_to_send->creation_date."\n" : '');
$log_detail = "\n";
} /* end while */
write_newsletter_detail($data_subscriber->id_subscription,
$data_subscriber->email,
'Y',
$log_detail);
}
else {
write_newsletter_detail($data_subscriber->id_subscription,
$data_subscriber->email,
'N',
NULL);
} /* end if mail_send */
} /* end while */
以及以下功能
function mail_send($rcpt_to,
$to_name,
$mail_from,
$from_name,
$subject,
$isHTML = true,
$body,
$attachment = NULL,
$direct_delivery = false,
$reply_to = NULL){
$mail = new PHPmailer;
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "mail@domain.com";
$mail->Password = "password";
$mail->Timeout = 3600;
$mail->addAddress(trim($rcpt_to), trim($to_name));
$mail->setFrom($mail_from,$from_name);
$mail->Subject = $subject;
$mail->Body = $body;
if ($isHTML) {
$mail->IsHTML(true);
$mail->AltBody = strip_tags($mail->Body);
}
if (IsSet($attachment)) {
$mail->AddAttachment($attachment['tmp_name'], $attachment['name']);
}
if (IsSet($reply_to)) {
$mail->AddReplyTo($reply_to);
}
if (!$mail->send()) {
return false;
} else {
return true;
}
}
我正在使用 PHPMailer 使用 gmail SMTP 服务器发送多封电子邮件。我有 4 个文件包含不同但几乎相同的代码来发送时事通讯。我的一个文件是将所有电子邮件发送给(约 60 个收件人)另外 3 个文件,每个文件都需要向约 600 个收件人发送一封电子邮件。问题出现在这里,一半的电子邮件被发送,其他的则没有。如果我运行该脚本,但这次为更少的收件人,女巫第一次没有收到电子邮件,它正在发送。
我在自己的域中使用 GMAIL。所以我没有超过任何限制。
什么可能导致这个问题?有任何想法吗 ?谢谢你。
更新**
SERVER -> CLIENT: 454 4.7.0 Too many login attempts, please try again later. e11sm950198edd.68 - gsmtp
在发送了一些电子邮件后,我收到了这个错误。任何想法为什么?
更新***
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent, reduces SMTP overhead
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->Username = "domain@domain.com";
$mail->Password = "password";
$mail->setFrom($site_noreply, $site_name);
$subjectnewsletter = 'Newsletter ['.date('d/m/Y', time()).']';
$mail->Subject = $subjectnewsletter;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
reset($subscriber);
while(list($i, $data_subscriber) = each($subscriber)) {
$email_counter = $i + 1;
echo ($email_counter).') '.$data_subscriber->field_1.' '.$data_subscriber->field_2.' - '.$data_subscriber->email.''."\n";
flush();
$language = $data_subscriber->lang;
$first_name_idx = $data_subscriber->field_1;
$last_name_idx = $data_subscriber->field_2;
$fullname = $first_name_idx.' '.$last_name_idx;
$bodymail = include($template_send_newsletter);
$mail->msgHTML($bodymail);
$mail->addAddress($data_subscriber->email, $fullname);
reset($data_subscriber->newsletter_item);
unset($log_detail);
$log_detail = "";
while(list($j, $list_of_news_to_send) = each($data_subscriber->newsletter_item)) {
$log_detail = ( IsSet($list_of_news_to_send->title) ? $list_of_news_to_send->title."\n" : '');
$log_detail = ( IsSet($list_of_news_to_send->subtitle) ? $list_of_news_to_send->subtitle."\n" : '');
$log_detail = ( IsSet($list_of_news_to_send->creation_date) ? $list_of_news_to_send->creation_date."\n" : '');
$log_detail = "\n";
} /* end while */
if (!$mail->send()) {
write_newsletter_detail($data_subscriber->id_subscription,
$data_subscriber->email,
'N',
NULL);
echo $mail->ErrorInfo;
break; //Abandon sending
} else {
write_newsletter_detail($data_subscriber->id_subscription,
$data_subscriber->email,
'Y',
$log_detail);
echo "Message sent";
}
$mail->clearAddresses();
$mail->clearAttachments();
} /* end while */
我设法更改了我的代码,因此它不会每封电子邮件都连接到 smtp 服务器。但是现在在它发送了 93 封电子邮件后,我收到了以下错误:
SMTP server error: MAIL FROM command failed