dqhnp44220 2018-05-31 17:49
浏览 116
已采纳

PHP mail()无法在消息内容中找到重音符号的解决方案

I have tried many solutions proposed about it, but still can't find the one that works. The email is sent succesfully but accents are in html code.

This is my code for the email content :

        $to_APPLICATION_RECEIVER = "w@z.ca";
        $from_APPLICATION_RECEIVER = "x@y.com";
        $subject_APPLICATION_RECEIVER = "Subject";
        $headers_APPLICATION_RECEIVER = 'From: "people" <x@y.com> 
';
        $headers_APPLICATION_RECEIVER .= 'Reply-to: x@y.com 
';

        //define boundary
        $semi_rand = md5(time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

        //tell header about $mime_boundary
        $headers_APPLICATION_RECEIVER .= "
MIME-Version: 1.0
";
        $headers_APPLICATION_RECEIVER .= "Content-Type: multipart/mixed;
";
        $headers_APPLICATION_RECEIVER .= " boundary=\"{$mime_boundary}\"";

        //Message section
        //$message = utf8_decode($message);
        $message_hed_APPLICATION_RECEIVER ="

--{$mime_boundary}
";
        $message_hed_APPLICATION_RECEIVER .="Content-Type: text/plain; charset=\"UTF-8\"
";
        $message_hed_APPLICATION_RECEIVER .="Content-Transfer-Encoding: 8bit

" . $message . "

";
        $message_hed_APPLICATION_RECEIVER .= "--{$mime_boundary}
";

The content of $message displayed by var_dump is "sfdféèî" but the email message content I receive is : sfdf&eacute;&egrave;&icirc;. Can someone help me with that? I have tried utf8_decode() and many other propositions on forums but still it ain't working. Thanks for your help guys.

  • 写回答

1条回答 默认 最新

  • dongsu1951 2018-05-31 18:00
    关注

    If you view the source of the page you will see that your string actually does contain the html entities. var_dump() will have hinted at this being the case like so:

    string(27) "sfdféèî"
    

    You can convert the entities back to UTF8 with:

    html_entity_decode('sfdf&eacute;&egrave;&icirc;')
    

    Which yields:

    string(10) "sfdféèî"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备