首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >更改发件人名称php mail而不是sitename@hostname.com

更改发件人名称php mail而不是sitename@hostname.com
EN

Stack Overflow用户
提问于 2011-12-03 13:29:35
回答 6查看 77.9K关注 0票数 27

我正在尝试从我的php发送电子邮件:

$to = 'it@7sisters.in';
    $email_from = "info@7sisters.in";

    $full_name = 'Suraj Hazarika';
    $from_mail = $full_name.'<'.$email_from.'>';



    $subject = "testing sender name";
    $message = "";
    $message .= '
            <p><strong>This is only a test . Please do not reply.</strong><br />
    ';
    $from = $from_mail;

    $headers = "" .
               "Reply-To:" . $from . "\r\n" .
               "X-Mailer: PHP/" . phpversion();
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";        
    mail($to,$subject,$message,$headers);

我正在遵循教程PHP E-mail Form Sender Name Instead Of E-mail?,但我仍然收到带有发送者名称和主机名的电子邮件。

     From                              Date             Subject 
sisters@rsx02.justhost.com  Fri, 11:24 pm       testing sender name
sisters@rsx02.justhost.com  Fri, 11:24 pm       testing sender name
EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2011-12-03 13:34:35

您只能在Reply-To标头中使用$from。如果你想让它出现在From头中,你需要在From头中设置它。

在您的mail()命令之前放入如下内容:

$headers .= 'From: ' . $from . "\r\n";
票数 25
EN

Stack Overflow用户

发布于 2012-11-21 13:37:58

我来到这个问题是为了寻找一些不同但有相似词汇的东西,所以这里是如何做我正在寻找的东西:

from标头中,将地址放在尖括号中,并将“发件人名称”放在尖括号之外。

from: Don Draper <don.draper@website.com>\n

我希望收件箱显示的是Don Draper而不是don.draper,这就是怎么做的。

票数 30
EN

Stack Overflow用户

发布于 2016-03-17 21:49:00

在标题行之前添加此行

$headers .= "From: Your Name <sitename@hostname.com> \r\n";

因此代码将是

$headers = "";
$headers .= "From: WIFI Metropolis <sitename@hostname.com> \r\n";
$headers .= "Reply-To:" . $from . "\r\n" ."X-Mailer: PHP/" . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";        
mail($to,$subject,$message,$headers);
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8365754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档