奇怪的字符出现在使用 PHP 发送的电子邮件的主题中


Strange character appearing in subject of email sent with PHP

我正在使用PHP邮件功能发送HTML电子邮件,在我的电子邮件主题中,我可以像这样。

Just one more step - Confirm Your Account†

我无法弄清楚"帐户"中是如何出现的,因为我从未将其放在变量上。以下是代码。

正在调用的函数

$html = template_registration($name, $email, $user_code);
sendmail($html, $email, $name, "Just one more step - Confirm Your Account‏");

function sendmail($html, $to, $name, $subject){
    require_once( site_path . "/framework/PHPMailer/PHPMailerAutoload.php" );
    $mail = new PHPMailer;
    $mail->isSendmail();
    $mail->setFrom('notifications@example.com', 'Example');
    $mail->addAddress($to, $name);
    $mail->Subject = $subject;
    $mail->msgHTML($html);
    if ( $mail->send() ) {
        return true;
    }
}

请帮忙,我什至不知道在谷歌上搜索什么。

您需要设置标头:

$headers = 'Content-Type: text/html; charset=UTF-8';
mail($to, $subject, $message, $headers);

否则,电子邮件将被错误地解释。

或者根据您的代码:

$mail->CharSet = 'UTF-8'; //before sending it of course

â€可能来自电子邮件的其余部分,但使用"错误"的编码,系统无法做出这种差异(非常容易)。

试试这个..您必须为电子邮件功能设置标题。下面的代码告诉您发送的数据类型。

$headers = "MIME-Version: 1.0" . "'r'n";
$headers .= "Content-type:text/html;charset=UTF-8" . "'r'n";