发送撇号('s)在电子邮件消息使用是错误编码使用PHP


Send apostrophe s ('s) in email message using was error encode using PHP?

发送撇号s ('s)在邮件消息使用是错误编码使用PHP ?

<?PHP
include("connect.php");
    $to      = "example@example.com";
    $subject = "TEST SUBJECT";
        $message = "peter’s test";
        $headers  = 'MIME-Version: 1.0' . "'r'n"; 
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
        $headers .= 'From: EXAMPLE <noreply@example.com>' . "'r'n";
        $headers .= 'Return-Path: return@example.com' . "'r'n";
        mail($to, $subject, $message, $headers, '-freturn@example.com');
?>

当我打开我的电子邮件,我看到peter’s ’s test

如何使用php在邮件消息中发送撇号s ('s) ?

您需要对包含撇号:

的字符串使用mb_convert_encoding
$message = mb_convert_encoding("peter’s test", 'UTF-8');

您正在邮件头中使用字符编码charset=iso-8859-1。我用的是utf-8,效果很好。尝试将charset=iso-8859-1替换为charset=utf-8