Change the sender name php mail instead of sitename@hostname.com

会有一股神秘感。 提交于 2019-11-27 20:33:49

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.

Put something like this before your mail() command:

$headers .= 'From: ' . $from . "\r\n";

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: Don Draper <don.draper@website.com>\n

I wanted the inbox to say Don Draper instead of don.draper and that's how to do it.

indextwo

You can also try adding the From address to the mail's 'envelope' by utilizing the fifth parameter in PHP's mail() function:

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 answer talks about updating sendmail's 'trusted users' with regards to this.

Add this line before header line

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

So the code will be

$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);

Simply add the From header. Something like this.

$headers .= "From: website@mydomainname.com";

Try to add From: to the header

$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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!