简体   繁体   English

发送PHP邮件时,如何在用户的电子邮件地址前显示其名称?

[英]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.

相关问题 使用PHP的mail()函数发送电子邮件时,如何自定义“发件人”字段? - How can I customize the 'From' field when sending and email with PHP's mail() function? 使用PHP将其输入MySql时,如何将用户输入附加到电子邮件地址(域部分)? - How can I append user input to an email address (domain part) when sending it to MySql with PHP? PHP邮件未将电子邮件发送到我的电子邮件地址 - PHP mail is not sending email to my email address 当发件人地址为yahoo时,php邮件功能不发送电子邮件 - php mail function not sending email when From address is yahoo php邮件未发送“无效的电子邮件地址” - php mail not sending “invalid email address” PHP如何将URL重定向到电子邮件地址并启动用户的邮件客户端 - PHP how to redirect url to email address and initiate user's mail client 使用PHP发送电子邮件时,如何“隐藏”实际的电子邮件地址? - How to 'hide' the actual email address when sending an email with PHP? 如何在PHP中发送邮件之前向用户发送响应 - How to send response to user before sending mail in php 在通过用户输入表单通过电子邮件发送消息时,如何包括发件人的姓名,而不仅仅是电子邮件地址 - How do I include sender's name and not just the email address while emailing message from user input form PHP邮件未发送电子邮件给Facebook用户 - PHP mail not sending email to facebook User
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM