更改发件人名称 php mail 而不是 [email protected]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8365754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change the sender name php mail instead of [email protected]
提问by Suraj Hazarika
I am trying to send email from my php :
我正在尝试从我的 php 发送电子邮件:
$to = '[email protected]';
$email_from = "[email protected]";
$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);
I am following the tutorial PHP E-mail Form Sender Name Instead Of E-mail?but I am still getting the emails with sender name with hostname.
我正在关注教程PHP 电子邮件表单发件人名称而不是电子邮件?但我仍然收到带有主机名的发件人姓名的电子邮件。
From Date Subject
[email protected] Fri, 11:24 pm testing sender name
[email protected] Fri, 11:24 pm testing sender name
回答by Trott
You only use $from
in your Reply-To
header. If you want it to be in the From
header, you need to set it in the From
header.
你只$from
在你的Reply-To
标题中使用。如果您希望它在From
标题中,则需要将其设置在From
标题中。
Put something like this before your mail()
command:
在你的mail()
命令之前放这样的东西:
$headers .= 'From: ' . $from . "\r\n";
回答by Ben
I came to this question looking for something different but with similar words, so here's how to do what I was looking for:
我来到这个问题寻找不同但相似的词,所以这里是如何做我正在寻找的东西:
In the from
header, put the address in angle brackets, and the "sender name" outside of it.
在from
标题中,将地址放在尖括号中,并将“发件人姓名”放在外面。
from: Don Draper <[email protected]>\n
I wanted the inbox to say Don Draper
instead of don.draper
and that's how to do it.
我想让收件箱说Don Draper
而不是,don.draper
这就是怎么做。
回答by indextwo
You can also try adding the From
address to the mail's 'envelope' by utilizing the fifth parameter in PHP's mail()
function:
您还可以尝试From
使用 PHPmail()
函数中的第五个参数将地址添加到邮件的“信封”中:
mail($to_mail, $subject, $message, $headers, "-f$from_email");
Reference here.
参考这里。
Reference regarding mail headers and envelopes here
关于邮件头和信封的参考在这里
Note that some server setups may disallow this or throw a warning, depending on their configuration and/or the configuration of the mail transfer agent. This answertalks about updating sendmail's 'trusted users' with regards to this.
请注意,某些服务器设置可能不允许这样做或发出警告,具体取决于它们的配置和/或邮件传输代理的配置。此答案讨论了更新 sendmail 的“受信任用户”与此相关。
回答by Ahmed Al Bermawy
Add this line before header line
在标题行之前添加这一行
$headers .= "From: Your Name <[email protected]> \r\n";
So the code will be
所以代码将是
$headers = "";
$headers .= "From: WIFI Metropolis <[email protected]> \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);
回答by Ben
Simply add the From header. Something like this.
只需添加 From 标头。像这样的东西。
$headers .= "From: [email protected]";
回答by Paulo H.
Try to add From:
to the header
尝试添加From:
到标题
$headers = "" .
"Reply-To:" . $from . "\r\n" .
"From:" . $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";
Some MTA can change/ignore this definition to avoid SPAM, and override with user of SMTP configured in PHP.ini
某些 MTA 可以更改/忽略此定义以避免垃圾邮件,并使用 PHP.ini 中配置的 SMTP 用户覆盖