2

我正在使用 PHPMailer 并通过我的 gmail 帐户使用 SMTP 发送电子邮件。这一切都有效,除非&主题中有一个,然后在我的收件箱中主题有&

有什么办法让这种情况不会发生?我试过设置字符集并对主题进行编码。

我的代码如下

$mail             = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug  = false;
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "tls";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 587;                   // set the SMTP port for the GMAIL server
$mail->Username   = "myusername@gmail.com";  // GMAIL username
$mail->Password   = "password";            // GMAIL password
$mail->SetFrom('from@somesite.com', 'From Person');
$mail->AddReplyTo("from@somesite.com", "From Person");
$mail->Subject    = 'An example with a & in the middle';
$mail->MsgHTML('Some text to send');
$mail->AddAddress('myusername@gmail.com');
$mail->Send()

谢谢你

4

1 回答 1

0

尝试使用此代码,让我知道它是否有帮助。

$mail->Subject    = "=?UTF-8?B?".base64_encode($_POST['subject'])."?=";
于 2013-10-18T13:36:27.397 回答