【问题标题】:PHP mail function doesn't encode french letters for mail subjectPHP邮件功能不编码邮件主题的法语字母
【发布时间】:2013-10-31 01:20:22
【问题描述】:

因此,电子邮件内容的编码有效,但主题的编码无效。我尝试了不同类型的编码,但它们似乎不起作用..请在这里帮助我。

所以我在收件箱中收到的是“ššuūūuķ”作为主题,并且在电子邮件的内容中一切正常。

$subject = $_POST['sub'];

$headers = "From: $name <$from>\nReply-To:$from\nReturn-Path:$from\nX-Mailer: PHP\n";
$limite = "_parties_".md5 (uniqid (rand()));
$headers .= "Date: ".date("l j F Y, G:i")."\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1"."\n";
$headers .= " boundary=\"----=$limite\"\n\n";

$message = '<html><body><table>';
$message .= '<tr>';
$message .= '<td colspan=2>'.$email_message.'</td>';
$message .= '</tr>';
$message .= '<tr>';
$message .= '<td height=10 colspan=2>'.$irack_id.'</td>';
$message .= '</tr>';
$message .= '</table>';
$message .= '</body>';
$message .= '</html>';

mail($to, $subject, $message, $headers);

【问题讨论】:

  • 你要发送什么到$subject
  • 我正在发送不同的法语信件。

标签: php email header encode


【解决方案1】:

您需要对法语字符进行编码。试试这个:

$subject = utf8_encode($_POST['sub']);

或者对标头进行编码

$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

【讨论】:

  • 是的,我之前已经尝试过了。当我收到电子邮件时,我得到的只是“������������������������ù ����������ë”。我发送的是“ùûüÿàâæçéèêêëùûüÿàâæçéèêëùûüÿàâæçéèêë”
  • 如果您在问题中提到这一点会有所帮助;)
  • �����������������关于此输出的任何新更新?
【解决方案2】:

https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/

$to = 'example@example.com';
$subject = 'Subject with non ASCII ó¿¡á';
$message = 'Message with non ASCII ó¿¡á';
$headers = 'From: example@example.com'."\r\n"
.'Content-Type: text/plain; charset=utf-8'."\r\n";
mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, $headers);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 2011-05-24
    • 1970-01-01
    相关资源
    最近更新 更多