[英]How do I display the user's name before the their email address when sending PHP mail?
For example in the Gmail application, when clicking "show details" there would be 例如,在Gmail应用程序中,单击“显示详细信息”时,
"To: whatever@gmail.com". “收件人:whatny@gmail.com”。 What I want is to show a full name before that, for example:"My Name whatever@gmail.com".
我想要的是在此之前显示全名,例如:“我的名字what@gmail.com”。
I think I would have to add something within $to = "whatever@gmail.com"
. 我想我必须在
$to = "whatever@gmail.com"
内添加一些$to = "whatever@gmail.com"
。 Any idea on how to achieve this? 关于如何实现这一点的任何想法? Thanks.
谢谢。
Copy/paste from the docs: 从文档中复制/粘贴:
$to_name = "Mary";
$to_address = "mary@example.com";
// Additional headers
$headers[] = 'To: '.$to_name.' <'.$to_address.'>, Kelly <kelly@example.com>'; // <-- this is what you want?
$headers[] = 'From: Birthday Reminder <birthday@example.com>';
$headers[] = 'Cc: birthdayarchive@example.com';
$headers[] = 'Bcc: birthdaycheck@example.com';
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
If you have the IMAP extension you can use imap_rfc822_write_address() . 如果您具有IMAP扩展名,则可以使用imap_rfc822_write_address() 。
echo imap_rfc822_write_address("hartmut", "example.com", "Hartmut Holzgraefe");
Or you can just wing it and hope everyone uses "safe" email addresses. 或者,您也可以打开它,希望每个人都使用“安全”的电子邮件地址。
echo "$name <$email>";
The actual header would be: 实际的标题为:
To: NameHere <email@example.com>\r\n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.