简体   繁体   English

更改发件人姓名PHP电子邮件?

[英]Change sender's name PHP email?

Okay, 好的,

So I have email notifications to my users setup but they receive it saying it's from notifications@domain.com. 因此,我向用户设置了电子邮件通知,但是他们收到了来自notifications@domain.com的消息。 Instead I want it to appear in their inbox as 'Name/Title' rather than the email address. 相反,我希望它在收件箱中显示为“姓名/标题”而不是电子邮件地址。

Here's what I've got so far: 这是我到目前为止所得到的:

$settings['notification'] = 'Notifications <notifications@domain.com>';

function nemail($to,$subject,$tpl,$var=array())
{
global $settings;
extract($var, EXTR_OVERWRITE);
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= 'From: '. trim($settings['notification']) . "\r\n" .
    'Reply-To: '. trim($settings['notification']) . "\r\n";
ob_start();
ob_implicit_flush(false);
require(realpath("themes/".$settings['theme']."/template/email_".$tpl.".php"));
$message = ob_get_clean();
@mail($to, $subject, $message, $headers);
}

As RTB says in his comment, you should look at using PHPMailer for emailing. 正如RTB在评论中所说,您应该考虑使用PHPMailer进行电子邮件发送。

But, I think the simple answer to your question would be to set the Sender header as well as the From - the RFC says you "should not" if the From header contains a single email, but it is not forbidden. 但是,我认为你的问题的简单答案是设置Sender标题以及From - RFC表示如果From标题包含单个电子邮件,则“不应该”,但不禁止。

http://tools.ietf.org/html/rfc2822#section-3.6.2 http://tools.ietf.org/html/rfc2822#section-3.6.2

你可以这样试试(来自http://php.net/manual/en/function.mail.php #Example 4)

$headers .= 'From: Blah Blah Blah <'.trim($settings['notification']) . ">' . "\r\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM