我们在使用PHP邮件程序通过循环逐个邮件发送时遇到一个问题。当邮件逐个发送时,邮件部分的主体只对某些接收者进行编码,而对于其他一些人来说,身体部分正常。请查看我们使用的代码。
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 = "mylogin@gmail.com"; // SMTP server username
$mail->Password = "mylogin"; // SMTP server password
$mail->From = "testo@host.com";
$mail->FromName = "$frommailid";
$mail->Encoding = 'base64';
$mail->ContentType = 'text/html; charset=UTF-8\r\n';
$to =$offmailid;
if($ccmailid!='')
{
$mail->AddCC($ccmailid);
}
$to='test@gmail.com';
$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;
答案 0 :(得分:0)
这里有些问题 - 你正在尝试做PHPMailer已经为你做的事情,并且可能会破坏它。
最明显的事情是设置ContentType - 只是不要这样做。
调用msghtml设置ishtml并设置altbody,因此您也不需要这样做。
我强烈建议您不要使用Base 64编码 - 使用quoted-printable编码。
不要在端口465上使用ssl。在端口587上使用tls。
这看起来就像你从一个旧例子开始 - 你是从Github运行最新的吗?