![](/img/trans.png)
[英]Using a sender's name and email address in the header of a PHP email form
[英]Change sender's name PHP email?
好的,
因此,我向用戶設置了電子郵件通知,但是他們收到了來自notifications@domain.com的消息。 相反,我希望它在收件箱中顯示為“姓名/標題”而不是電子郵件地址。
這是我到目前為止所得到的:
$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);
}
正如RTB在評論中所說,您應該考慮使用PHPMailer進行電子郵件發送。
但是,我認為你的問題的簡單答案是設置Sender標題以及From - RFC表示如果From標題包含單個電子郵件,則“不應該”,但不禁止。
你可以這樣試試(來自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.