phpmailer w/smtp在几百封电子邮件之后到Mailgun,获得错误:451无法解析标题:畸形数据;意外的EOF
使用phpmailer v 6.6.0与SMTP使用MailGun运行PHP 7.4.28& mysql。以下代码是在一个foreach循环中生成1000多封电子邮件。可以在本地发送电子邮件(使用phpmailer)无问题,但是在发送了一百个或更多电子邮件后,通过SMTP将外部发送到MailGun,将出现SMTP通信错误。 phpmailer调试报告的最后两个条目,#145被发送,#146遇到了通信错误。 MailGun说,该错误是解析MIME标头数据畸形的错误。因此,我将所有标头项目的Charset设置为UTF-8,并在phpmailer中宣布这一点,但仍然不正确。
这是MailGuns官方答复: “由于'451无法解析标头:畸形的数据;意外的eof',这并不能提供有关该错误到底是什么的具体信息。但是,这意味着消息哑M正在畸形。这可以是因为特殊字符或无效格式,但我们又一次不知道具体细节。”
以下是phpmailer调试报告的最后两个条目。在#145的开始和#146的结束时,切断了几十条线,在发生错误的情况下,请不要标记为垃圾邮件。
145
...removed above lines so as not to be flagged as spam...
2022-05-27 22:40:33 CLIENT -> SERVER: This is a multi-part message in MIME format.
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: --b1_qTte9OeCLb4bnOH0adZvABlTFkh21zO3VRKOPoXHBs
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Type: text/plain; charset=utf-8
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Transfer-Encoding: base64
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: NS0yNy0yMjxicj5BbHRCb2R5OiBUaGlzIGlzIGEgQnVsayBSZWxheSBFbWFpbCAoU01UUCkgVGVz
2022-05-27 22:40:33 CLIENT -> SERVER: dCAvci9uIFZpYSBQSFAgNy40LjI4LCBQSFBNYWlsZXIgNi42LjAgYW5kIE1haWxndW4gd2l0aCBI
2022-05-27 22:40:33 CLIENT -> SERVER: VE1MICYgUEhQTWFpbGVyIENoYXJTZXQgPSAndXRmLTgnICwgTXlTUUwgdXRmOG1iNCA9ICd1dGY4
2022-05-27 22:40:33 CLIENT -> SERVER: bWI0JywgYW5kIFBIUE1haWxlciBFbmNvZGluZyA9ICdxdW90ZWQtcHJpbnRhYmxlJyBhbmQgdXRm
2022-05-27 22:40:33 CLIENT -> SERVER: OF9lbmNvZGUgYmVmb3JlIGVhY2ggaGVhZGVyIGVsZW1lbnQ=
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: --b1_qTte9OeCLb4bnOH0adZvABlTFkh21zO3VRKOPoXHBs
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Type: text/html; charset=utf-8
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Transfer-Encoding: base64
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: PHA+NS0yNy0yMjxicj5Cb2R5OiBUaGlzIGlzIGEgQnVsayBSZWxheSBFbWFpbCAoU01UUCkgVGVz
2022-05-27 22:40:33 CLIENT -> SERVER: dDxicj5WaWEgUEhQIDcuNC4yOCwgUEhQTWFpbGVyIDYuNi4wIGFuZCBNYWlsZ3VuIHdpdGggSFRN
2022-05-27 22:40:33 CLIENT -> SERVER: TCAmIFBIUE1haWxlciBDaGFyU2V0ID0gIlVURi04IiAsIE15U1FMICRjaGFyc2V0ID0gInV0Zjht
2022-05-27 22:40:33 CLIENT -> SERVER: YjQiLCBhbmQgUEhQTWFpbGVyIEVuY29kaW5nID0gInF1b3RlZC1wcmludGFibGUiIGFuZCB1dGY4
2022-05-27 22:40:33 CLIENT -> SERVER: X2VuY29kZSBiZWZvcmUgZWFjaCBoZWFkZXIgZWxlbWVudDwvcD4=
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: --b1_qTte9OeCLb4bnOH0adZvABlTFkh21zO3VRKOPoXHBs--
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: .
2022-05-27 22:40:34 SERVER -> CLIENT: 250 Great success
2022-05-27 22:40:34 CLIENT -> SERVER: RSET
2022-05-27 22:40:34 SERVER -> CLIENT: 250 OK
Message ([email protected]) has been sent successfully
146
2022-05-27 22:40:35 CLIENT -> SERVER: QUIT
2022-05-27 22:40:35 SERVER -> CLIENT: 221 See you later. Yours truly, Mailgun
2022-05-27 22:40:35 Connection: closed
2022-05-27 22:40:35 Connection: opening to smtp.mailgun.org:587, timeout=300, options=array()
2022-05-27 22:40:35 Connection: opened
2022-05-27 22:40:35 SERVER -> CLIENT: 220 Mailgun Influx ready
2022-05-27 22:40:35 CLIENT -> SERVER: EHLO www.company.com
2022-05-27 22:40:35 SERVER -> CLIENT: 250-smtp-out-n03.prod.us-west-2.postgun.com250-AUTH PLAIN LOGIN250-SIZE 52428800250-8BITMIME250-SMTPUTF8250-PIPELINING250 STARTTLS
2022-05-27 22:40:35 CLIENT -> SERVER: STARTTLS
2022-05-27 22:40:35 SERVER -> CLIENT: 220 Go ahead
2022-05-27 22:40:35 CLIENT -> SERVER: EHLO www.company.com
2022-05-27 22:40:35 SERVER -> CLIENT: 250-smtp-out-n03.prod.us-west-2.postgun.com250-AUTH PLAIN LOGIN250-SIZE 52428800250-8BITMIME250-SMTPUTF8250 PIPELINING
2022-05-27 22:40:35 CLIENT -> SERVER: AUTH LOGIN
2022-05-27 22:40:35 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2022-05-27 22:40:35 CLIENT -> SERVER: [credentials hidden]
2022-05-27 22:40:35 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2022-05-27 22:40:35 CLIENT -> SERVER: [credentials hidden]
2022-05-27 22:40:36 SERVER -> CLIENT: 235 Authentication successful
2022-05-27 22:40:36 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2022-05-27 22:40:36 SERVER -> CLIENT: 250 Sender address accepted
2022-05-27 22:40:36 CLIENT -> SERVER: RCPT TO:<[email protected]>
2022-05-27 22:40:36 SERVER -> CLIENT: 250 Recipient address accepted
2022-05-27 22:40:36 CLIENT -> SERVER: DATA
2022-05-27 22:40:36 SERVER -> CLIENT: 354 Continue
2022-05-27 22:40:36 CLIENT -> SERVER: Date: Fri, 27 May 2022 17:40:35 -0500
2022-05-27 22:40:36 CLIENT -> SERVER: To: Ryne Allen <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: From: My Company <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: Reply-To: My Company <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: Subject: #146g-SMTP-MG-Test -> To: 10591 of [email protected]
2022-05-27 22:40:36 CLIENT -> SERVER: Message-ID: <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: X-Mailer: PHPMailer 6.6.0 (https://github.com/PHPMailer/PHPMailer)
2022-05-27 22:40:36 CLIENT -> SERVER: MIME-Version: 1.0
2022-05-27 22:40:36 CLIENT -> SERVER: Content-Type: multipart/alternative;
2022-05-27 22:40:36 CLIENT -> SERVER: boundary="b1_uBrObwrxzuPlfV2uIa8T2UUNuG4VAPAYqyNHqCgy24"
2022-05-27 22:40:36 CLIENT -> SERVER:
2022-05-27 22:40:36 CLIENT -> SERVER: This is a multi-part message in MIME format.
2022-05-27 22:40:36 CLIENT -> SERVER:
2022-05-27 22:40:36 CLIENT -> SERVER: 0krd GaOmW,:36u0ZoeKeWKeWKX t.j5yIZ hctyllnNAnaRn l t.ZlUB1ATCuSAu1UhZNpZu1UhZNpZBR4pf-Rn l t.ZlUB1ATCuSAu1UhZNpZu1UhZNpZBR4pf-Rn l undara0iipanzWT:l_NT -> SERVER:
2022-05-27 22:40:36 CLIENT -> SERVER: 0krd GaOmW,:36u0ZoeKeWKeWp2.
2022-05-27 22:40:36 CLIENT --1e: mIR7VER: This is a multi-part SERVER: 0krd GaOmW,:36u0ZoeKeWKeWp2.
2022-05-27 22:40:36 CLIENT -> SERVER:
2022-.W,:36u0ZoeKeWKeWKX t.j5yIZ hctyllnIJ9IWeKeWeoeKeWKeWKX t.j5yIZ hctyllnNAnaRn l t.ZlUB1ATCuSAua40:3VF4 I mUmUmUmUala::: Ga l t.ZlUNidJ@dDWllDWllDSDeITCEFIpe-GGa l t.ZlUNidJ@dDWllDWllDSDeITCEFIpe-GGa l t.ZlUNidJ@dDWllDWllDSDeITCEFIpe-GGa l t.ZlUNidJ@dDWllDWu5Do1slUNidJ@dDWllDWu5Do1slUNidJ@dDWllDWu5Do1slUNidJ@ 05-27 22:40:36 CLIENT --1e: mIR7VER: This is a muXSllDWIvE hdsttbtC IT5kbxe pGJ@dDip
...removed last few dozen lines so not to be flagged as spam...
这是我用来使用phpmailer向MailGun发送批量电子邮件的代码:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//PHPMailer Ver 6.6.0
require '../../PHPMailer/src/PHPMailer.php';
require '../../PHPMailer/src/SMTP.php';
require '../../PHPMailer/src/Exception.php';
$setFrom = utf8_encode('[email protected]');
$FromNam = utf8_encode('My Company');
$ReplyTo = utf8_encode('[email protected]');
$ReplNam = utf8_encode('My Company');
$Address = utf8_encode('[email protected]');
$AddrNam = utf8_encode('Ryne Allen');
$Subject = utf8_encode('#'.$count.'h-SMTP-MG-Test -> To: '.$row["mnrID"].' of '.$row["cont_email"]);
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8';
$mail->Encoding = 'base64';
$mail->isSMTP();
$mail->SMTPKeepAlive = true;
$mail->Host = 'smtp.mailgun.org';
$mail->Port = '587';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'xxxxxx';
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = 3;
$mail->setFrom($setFrom, $FromNam);
$mail->addReplyTo($ReplyTo, $ReplNam);
$mail->addAddress($Address, $AddrNam);
$mail->isHTML(true);
$mail->Subject = $Subject;
//An HTML message body
$mail->Body = utf8_encode('<p>5-27-22<br>Body: This is a Bulk Relay Email (SMTP) Test<br>Via PHP 7.4.28, PHPMailer 6.6.0 and Mailgun with HTML & PHPMailer CharSet = "utf-8" , MySQL $charset = "utf8mb4", and PHPMailer Encoding = "base64" and utf8_encode before each header element</p>');
$mail->AltBody = utf8_encode("5-27-22<br>AltBody: This is a Bulk Relay Email (SMTP) Test /r/n Via PHP 7.4.28, PHPMailer 6.6.0 and Mailgun with HTML & PHPMailer CharSet = 'utf-8' , MySQL $charset = 'utf8mb4', and PHPMailer Encoding = 'base64' and utf8_encode before each header element");
try {
$mail->send();
echo "<br>Message (".$row["cont_email"].") has been sent successfully<br>";
} catch (Exception $e) {
echo 'Message could not be sent.';
echo "Mailer Error: " . $mail->ErrorInfo;
}
任何帮助都将不胜感激。我尝试设置$ ail-&gt; encoding ='quoted printable'而不是'base64'和$ aim-&gt; charset ='utf-8'而不是我阅读的较低案例'utf-8'问题。
Using PHPMailer v 6.6.0 with SMTP to MailGun running PHP 7.4.28 & MySQL. The below code is in a foreach loop generating over 1,000 emails. Can send emails locally (using PHPMailer) without issue, but when sending externally via SMTP to MailGun, after a hundred or more emails have been sent, will have an SMTP communication error. Last two entries of PHPMailer Debugging report, #145 was sent w/out issue, #146 had a communication error. MailGun is saying the error is a parsing one where the MIME header data is malformed. So I set charset to utf-8 for all header items and declared that in PHPMailer, but something is still not right.
Here is MailGuns official reply:
"With the '451 Failed to parse header: malformed data; unexpected EOF', it doesn't give specifics as to what exactly caused that error. However, it means that the message MIME is coming in malformed. This can be because of special characters or invalid formatting, but again we don't know specifics."
Below is the last two entries of the PHPMailer Debugging Report. Cut off a few dozen lines at beginning of #145 and the end of #146 where error occurred so not to be flagged as spam.
145
...removed above lines so as not to be flagged as spam...
2022-05-27 22:40:33 CLIENT -> SERVER: This is a multi-part message in MIME format.
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: --b1_qTte9OeCLb4bnOH0adZvABlTFkh21zO3VRKOPoXHBs
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Type: text/plain; charset=utf-8
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Transfer-Encoding: base64
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: NS0yNy0yMjxicj5BbHRCb2R5OiBUaGlzIGlzIGEgQnVsayBSZWxheSBFbWFpbCAoU01UUCkgVGVz
2022-05-27 22:40:33 CLIENT -> SERVER: dCAvci9uIFZpYSBQSFAgNy40LjI4LCBQSFBNYWlsZXIgNi42LjAgYW5kIE1haWxndW4gd2l0aCBI
2022-05-27 22:40:33 CLIENT -> SERVER: VE1MICYgUEhQTWFpbGVyIENoYXJTZXQgPSAndXRmLTgnICwgTXlTUUwgdXRmOG1iNCA9ICd1dGY4
2022-05-27 22:40:33 CLIENT -> SERVER: bWI0JywgYW5kIFBIUE1haWxlciBFbmNvZGluZyA9ICdxdW90ZWQtcHJpbnRhYmxlJyBhbmQgdXRm
2022-05-27 22:40:33 CLIENT -> SERVER: OF9lbmNvZGUgYmVmb3JlIGVhY2ggaGVhZGVyIGVsZW1lbnQ=
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: --b1_qTte9OeCLb4bnOH0adZvABlTFkh21zO3VRKOPoXHBs
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Type: text/html; charset=utf-8
2022-05-27 22:40:33 CLIENT -> SERVER: Content-Transfer-Encoding: base64
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: PHA+NS0yNy0yMjxicj5Cb2R5OiBUaGlzIGlzIGEgQnVsayBSZWxheSBFbWFpbCAoU01UUCkgVGVz
2022-05-27 22:40:33 CLIENT -> SERVER: dDxicj5WaWEgUEhQIDcuNC4yOCwgUEhQTWFpbGVyIDYuNi4wIGFuZCBNYWlsZ3VuIHdpdGggSFRN
2022-05-27 22:40:33 CLIENT -> SERVER: TCAmIFBIUE1haWxlciBDaGFyU2V0ID0gIlVURi04IiAsIE15U1FMICRjaGFyc2V0ID0gInV0Zjht
2022-05-27 22:40:33 CLIENT -> SERVER: YjQiLCBhbmQgUEhQTWFpbGVyIEVuY29kaW5nID0gInF1b3RlZC1wcmludGFibGUiIGFuZCB1dGY4
2022-05-27 22:40:33 CLIENT -> SERVER: X2VuY29kZSBiZWZvcmUgZWFjaCBoZWFkZXIgZWxlbWVudDwvcD4=
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: --b1_qTte9OeCLb4bnOH0adZvABlTFkh21zO3VRKOPoXHBs--
2022-05-27 22:40:33 CLIENT -> SERVER:
2022-05-27 22:40:33 CLIENT -> SERVER: .
2022-05-27 22:40:34 SERVER -> CLIENT: 250 Great success
2022-05-27 22:40:34 CLIENT -> SERVER: RSET
2022-05-27 22:40:34 SERVER -> CLIENT: 250 OK
Message ([email protected]) has been sent successfully
146
2022-05-27 22:40:35 CLIENT -> SERVER: QUIT
2022-05-27 22:40:35 SERVER -> CLIENT: 221 See you later. Yours truly, Mailgun
2022-05-27 22:40:35 Connection: closed
2022-05-27 22:40:35 Connection: opening to smtp.mailgun.org:587, timeout=300, options=array()
2022-05-27 22:40:35 Connection: opened
2022-05-27 22:40:35 SERVER -> CLIENT: 220 Mailgun Influx ready
2022-05-27 22:40:35 CLIENT -> SERVER: EHLO www.company.com
2022-05-27 22:40:35 SERVER -> CLIENT: 250-smtp-out-n03.prod.us-west-2.postgun.com250-AUTH PLAIN LOGIN250-SIZE 52428800250-8BITMIME250-SMTPUTF8250-PIPELINING250 STARTTLS
2022-05-27 22:40:35 CLIENT -> SERVER: STARTTLS
2022-05-27 22:40:35 SERVER -> CLIENT: 220 Go ahead
2022-05-27 22:40:35 CLIENT -> SERVER: EHLO www.company.com
2022-05-27 22:40:35 SERVER -> CLIENT: 250-smtp-out-n03.prod.us-west-2.postgun.com250-AUTH PLAIN LOGIN250-SIZE 52428800250-8BITMIME250-SMTPUTF8250 PIPELINING
2022-05-27 22:40:35 CLIENT -> SERVER: AUTH LOGIN
2022-05-27 22:40:35 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2022-05-27 22:40:35 CLIENT -> SERVER: [credentials hidden]
2022-05-27 22:40:35 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2022-05-27 22:40:35 CLIENT -> SERVER: [credentials hidden]
2022-05-27 22:40:36 SERVER -> CLIENT: 235 Authentication successful
2022-05-27 22:40:36 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2022-05-27 22:40:36 SERVER -> CLIENT: 250 Sender address accepted
2022-05-27 22:40:36 CLIENT -> SERVER: RCPT TO:<[email protected]>
2022-05-27 22:40:36 SERVER -> CLIENT: 250 Recipient address accepted
2022-05-27 22:40:36 CLIENT -> SERVER: DATA
2022-05-27 22:40:36 SERVER -> CLIENT: 354 Continue
2022-05-27 22:40:36 CLIENT -> SERVER: Date: Fri, 27 May 2022 17:40:35 -0500
2022-05-27 22:40:36 CLIENT -> SERVER: To: Ryne Allen <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: From: My Company <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: Reply-To: My Company <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: Subject: #146g-SMTP-MG-Test -> To: 10591 of [email protected]
2022-05-27 22:40:36 CLIENT -> SERVER: Message-ID: <[email protected]>
2022-05-27 22:40:36 CLIENT -> SERVER: X-Mailer: PHPMailer 6.6.0 (https://github.com/PHPMailer/PHPMailer)
2022-05-27 22:40:36 CLIENT -> SERVER: MIME-Version: 1.0
2022-05-27 22:40:36 CLIENT -> SERVER: Content-Type: multipart/alternative;
2022-05-27 22:40:36 CLIENT -> SERVER: boundary="b1_uBrObwrxzuPlfV2uIa8T2UUNuG4VAPAYqyNHqCgy24"
2022-05-27 22:40:36 CLIENT -> SERVER:
2022-05-27 22:40:36 CLIENT -> SERVER: This is a multi-part message in MIME format.
2022-05-27 22:40:36 CLIENT -> SERVER:
2022-05-27 22:40:36 CLIENT -> SERVER: 0krd GaOmW,:36u0ZoeKeWKeWKX t.j5yIZ hctyllnNAnaRn l t.ZlUB1ATCuSAu1UhZNpZu1UhZNpZBR4pf-Rn l t.ZlUB1ATCuSAu1UhZNpZu1UhZNpZBR4pf-Rn l undara0iipanzWT:l_NT -> SERVER:
2022-05-27 22:40:36 CLIENT -> SERVER: 0krd GaOmW,:36u0ZoeKeWKeWp2.
2022-05-27 22:40:36 CLIENT --1e: mIR7VER: This is a multi-part SERVER: 0krd GaOmW,:36u0ZoeKeWKeWp2.
2022-05-27 22:40:36 CLIENT -> SERVER:
2022-.W,:36u0ZoeKeWKeWKX t.j5yIZ hctyllnIJ9IWeKeWeoeKeWKeWKX t.j5yIZ hctyllnNAnaRn l t.ZlUB1ATCuSAua40:3VF4 I mUmUmUmUala::: Ga l t.ZlUNidJ@dDWllDWllDSDeITCEFIpe-GGa l t.ZlUNidJ@dDWllDWllDSDeITCEFIpe-GGa l t.ZlUNidJ@dDWllDWllDSDeITCEFIpe-GGa l t.ZlUNidJ@dDWllDWu5Do1slUNidJ@dDWllDWu5Do1slUNidJ@dDWllDWu5Do1slUNidJ@ 05-27 22:40:36 CLIENT --1e: mIR7VER: This is a muXSllDWIvE hdsttbtC IT5kbxe pGJ@dDip
...removed last few dozen lines so not to be flagged as spam...
This is the code I used to send bulk email using PHPMailer to MailGun:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//PHPMailer Ver 6.6.0
require '../../PHPMailer/src/PHPMailer.php';
require '../../PHPMailer/src/SMTP.php';
require '../../PHPMailer/src/Exception.php';
$setFrom = utf8_encode('[email protected]');
$FromNam = utf8_encode('My Company');
$ReplyTo = utf8_encode('[email protected]');
$ReplNam = utf8_encode('My Company');
$Address = utf8_encode('[email protected]');
$AddrNam = utf8_encode('Ryne Allen');
$Subject = utf8_encode('#'.$count.'h-SMTP-MG-Test -> To: '.$row["mnrID"].' of '.$row["cont_email"]);
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8';
$mail->Encoding = 'base64';
$mail->isSMTP();
$mail->SMTPKeepAlive = true;
$mail->Host = 'smtp.mailgun.org';
$mail->Port = '587';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'xxxxxx';
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = 3;
$mail->setFrom($setFrom, $FromNam);
$mail->addReplyTo($ReplyTo, $ReplNam);
$mail->addAddress($Address, $AddrNam);
$mail->isHTML(true);
$mail->Subject = $Subject;
//An HTML message body
$mail->Body = utf8_encode('<p>5-27-22<br>Body: This is a Bulk Relay Email (SMTP) Test<br>Via PHP 7.4.28, PHPMailer 6.6.0 and Mailgun with HTML & PHPMailer CharSet = "utf-8" , MySQL $charset = "utf8mb4", and PHPMailer Encoding = "base64" and utf8_encode before each header element</p>');
$mail->AltBody = utf8_encode("5-27-22<br>AltBody: This is a Bulk Relay Email (SMTP) Test /r/n Via PHP 7.4.28, PHPMailer 6.6.0 and Mailgun with HTML & PHPMailer CharSet = 'utf-8' , MySQL $charset = 'utf8mb4', and PHPMailer Encoding = 'base64' and utf8_encode before each header element");
try {
$mail->send();
echo "<br>Message (".$row["cont_email"].") has been sent successfully<br>";
} catch (Exception $e) {
echo 'Message could not be sent.';
echo "Mailer Error: " . $mail->ErrorInfo;
}
Any help would be appreciated. I tried setting $mail->Encoding = 'quoted-printable' instead of 'base64' and the $mail->CharSet = 'UTF-8' instead of the lower case 'utf-8' which I read may exclude more problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没什么明显的,但是您正在做几件事不太正确。
您不应该在PHP 7.4上进行任何新的开发。它是从活动支持中,并且很快就会停止获得安全补丁。
避免
utf8_encode
函数;无论如何,您的代码和数据都应在UTF-8中,如果是,则该功能会损坏您的文本。它已经在PHP 9 中将被删除。端口
期望一个整数,而不是字符串;使用$邮件 - &gt; port = 587
。不要将base64编码用于HTML零件;它使您看起来像垃圾邮件发送者,只需让phpmailer使用其默认编码(8位,Mailgun支持)。
您正在设置
smtpkeepalive
,但是您没有发送循环,因此它不会实现任何目标。请参阅 phpmailer邮件列表示例。这应该使您的发送速度更快。现在到您的数据上:
这里有些不对劲。它看起来像内存损坏或其他内容(不是网络,因为当时是本地的)。
客户端 - &gt;服务器
字符串是phpmailer中简单的静态文本,没有机会包含其他任何东西。我建议您应用上面的其他更改,看看您如何去。Nothing obvious, but you're doing several things not quite right.
You shouldn't be doing any new development on PHP 7.4. It's out of active support, and will stop getting security patches soon.
Avoid the
utf8_encode
function; your code and data should be in UTF-8 anyway, and if it is, that function will corrupt your text. It's sufficiently dangerous that it's been deprecated for PHP 8.2 and will be removed in PHP 9.Port
expects an integer, not a string; use$mail->Port = 587
.Don't use base64 encoding for HTML parts; it makes you look like a spammer, just let PHPMailer use its default encoding (8-bit, which MailGun supports).
You're setting
SMTPKeepAlive
, but you have no sending loop, so it will not achieve anything. See the PHPMailer mailing list example for how to use that correctly. This should make your send go quite a bit faster.Now onto your data:
There is something very wrong here. It looks like memory corruption or something (not network, as it's local at that point). The
CLIENT -> SERVER
string is simple static text in PHPMailer, and there is no opportunity for it to contain anything else. I'd suggest applying the other changes above, and see how you go.我尝试了多个电子邮件继电器服务,并与MailJet,SendGrid和Sendinblue产生了类似的结果。
Synchro的回应包括:“您正在设置SMTPKeepalive,但您没有发送循环,因此它不会取得任何成就。”这使我质疑操作的逻辑,而不是围绕phpmailer代码创建循环,而是在phpmailer代码中创建它,使SMTP会话保持活力,直到发送了所有[Bulk]电子邮件。
在一次发送多个(数百个)电子邮件时,我能够通过更改phpmailer逻辑来解决此问题。
新代码看起来像这样:
I tried multiple email relay services and had similar results with MailJet, SendGrid, and SendinBlue.
Synchro's response included, "You're setting SMTPKeepAlive, but you have no sending loop, so it will not achieve anything." This made me question the logic of the operation and instead of creating the loop around the PHPMailer code, I created it within the PHPMailer code, keeping the SMTP session alive until all [bulk] emails were sent out.
I was able to fix this issue by changing the PHPMailer logic when sending out multiple (hundreds) of emails at once.
The new code looks like this: