0
我們在使用PHP郵件程序通過循環發送逐個郵件時遇到了一個問題。當郵件逐一發送時,郵件的正文部分只會被編碼,而對於其他一些郵件,身體部分會很好。請查看我們使用的代碼。在發送php郵件中的多個郵件時發生HTML轉換問題
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$mail->CharSet = "text/html; charset=UTF-8;";
$mail->IsSMTP(); // tell the class to use SMTP
$mail->CharSet='UTF-8';
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 465; // set the SMTP server port
$mail->Host = "ssl://smtp.googlemail.com"; // SMTP server
$mail->Username = "[email protected]"; // SMTP server username
$mail->Password = "mylogin"; // SMTP server password
$mail->From = "[email protected]";
$mail->FromName = "$frommailid";
$mail->Encoding = 'base64';
$mail->ContentType = 'text/html; charset=UTF-8\r\n';
$to =$offmailid;
if($ccmailid!='')
{
$mail->AddCC($ccmailid);
}
$to='[email protected]';
$mail->AddAddress($to);
$mail->Subject =$subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
//echo "mail sent";
}
catch (phpmailerException $e)
{
// echo $e->errorMessage();
}
output :
y="----=neXtPaRt_1413635021"
------=neXtPaRt_1413635021
Content-Type: multipart/alternative;
boundary="b1_d42b7a92f948fa93f11ba35ba7f81fe2"
--b1_d42b7a92f948fa93f11ba35ba7f81fe2
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
VG8gdmlldyB0aGUgbWVzc2FnZSwgcGxlYXNlIHVzZSBhbiBIVE1MIGNvbXBhdGlibGUgZW1haWwg
dmlld2VyIQ0K
--b1_d42b7a92f948fa93f11ba35ba7f81fe2
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64
RGVhciBUZXN0ZW1wbG95ZWUgLDxicj48YnI+IFlvdXIgbGVhdmUgZnJvbSBPY3QgMjEsMjAxNCB0
byBPY3QgMjEsMjAxNCBhcHBsaWVkIG9uIE9jdCAxOCwyMDE0IGhhcyBiZWVuIGFwcHJvdmVkLjxi
cj48YnI+Q29tbWVudHMgOjxicj48YnI+IFJlZ2FyZHMsPGJyPlNoaW1uYSBDPGJyPlNvZnR3YXJl
IEVuZ2luZWVyPGJyPg==
--b1_d42b7a92f948fa93f11ba35ba7f81fe2--
------=neXtPaRt_1413635021
Content-Type: text/plain;
我已經從sGithub下載了最新的phpmailer - 直到不能正常工作 – 2014-10-28 07:12:38
你有沒有做過我建議的其他任何事情? 「仍然無法正常工作」並不能告訴你問題是什麼。 – Synchro 2014-10-28 07:54:19
無論您有什麼建議,我都做了所有更改。在將端口587上的「SSL」更改爲「TLS」後,它對所有郵件都正常工作。我添加了下面提到的代碼。 $ mail-> SMTPSecure ='tls'; $ mail-> Port = 587;端口 $ mail-> Host =「smtp.gmail.com」; $ mail-> Mailer =「smtp」;這工作正常。感謝Synchro。 – 2014-10-28 09:26:28