douken1726 2015-07-29 06:17
浏览 46
已采纳

无法在WordPress中发送多个PHP mail()标头

I am using Gravity Forms to handle forms and after the form submission I have coded a simple mail() function to send an email to the user. The headers work fine individually:

$headers = 'From: MyName
';

// or 

$headers .= 'Content-type: text/html; charset=iso-8859-1
';

mail('me@gmail.com', 'My Subject', 'My Content', $headers);

but together in either order there is an issue"

$headers = 'From: MyName
'; // works fine
$headers .= 'Content-type: text/html; charset=iso-8859-1
'; // In this case the body is not rendered as HTML
// or
$headers = 'Content-type: text/html; charset=iso-8859-1
'; // renders as HTML
$headers .= 'From: MyName
'; // This now gives "unknown sender"

Any ideas?

  • 写回答

1条回答 默认 最新

  • duanbei3747 2015-07-29 07:30
    关注

    Line breaks need to be double-quoted in order for " " to be respected. As the headers are currently defined, ' ' is being treated as literal text, not a line break.

    $headers = "From: MyName
    ";
    $headers .= "Content-type: text/html; charset=iso-8859-1
    "; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部