doudou1897 2012-03-16 18:38
浏览 59
已采纳

如何为PHP邮件添加自定义标头?

I have a mail function with the standard parameters:

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

Where:

$headers = "From: admin@mysite.org";
$headers .= "
Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 

Now, I'm trying to get the sent e-mails to show 'My Site' as the sender instead of 'admin@mysite.org' but if someone responds to the mail it still needs to go to admin@mysite.org.

I've tried putting "My Site" in the "From" field before and after the e-mail address but it just appends to the address. I've tried appending it to the $headers variable but that messes the whole e-mail up. I've also tried adding it this way:

$headers .= "
My Site";

but that doesn't seem to do anything.

I know this can't be complicated as I've seen it done a hundred times, but I can't seem to find a straight-forward answer for this - how do I 'mask' the admin e-mail with the site name but still keep it as the address any response goes to?

  • 写回答

2条回答 默认 最新

  • duancashi1362 2012-03-16 18:43
    关注

    Change your From: header to "From: My Site <admin@mysite.org>"

    $headers = "From: My Site <admin@mysite.org>";
    $headers .= "
    Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
    

    From the PHP Docs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件