简体   繁体   English

如何让PHPMailer忽略'from'电子邮件地址并仅显示名称?

[英]How to make PHPMailer ignoring the 'from' email address and display only the name?

I'm using PHPMailer with the same SMTP configuration as my outlook. 我正在使用与我的Outlook相同的SMTP配置的PHPMailer。

Let's say that my email is "b@example.com" and name is "Bob, b". 假设我的电子邮件是“b@example.com”,名称是“Bob,b”。 When I send a mail from my outlook to "Alice" at "a@example.com". 当我从我的Outlook发送邮件到“Alice”时,请发送电子邮件至“a@example.com”。 In her outlook client she will only see "Bob, b" and she will not see my email address in the header. 在她的Outlook客户端中,她只会看到“Bob,b”,并且她不会在标题中看到我的电子邮件地址。

When sending the same mail from "PHPMailer" Alice will see in her outlook "Bob, b {b@example.com}" 当从“PHPMailer”发送相同的邮件时,Alice将在她的展望中看到“Bob,b {b@example.com}”

When I tried to set it without the email: 当我尝试在没有电子邮件的情况下设置它:

$mail->setFrom('Bob, b');

The smtp added {root@mysmtpblabla.example.com} smtp添加了{root@mysmtpblabla.example.com}

Can PHPMailer handler such a case? PHPMailer处理程序可以这样的情况吗? sending with name only? 只发送名字?

It really helps to actually read the docs for the function you're calling . 真正有助于实际阅读您正在调用的函数的文档

Applying that info to your example, you should do this: 将该信息应用于您的示例,您应该这样做:

$mail->setFrom("b@example.com", "Bob, b");

In most email clients it will display the name and not the email - in Outlook or Apple Mail it will usually show you the email address next to the name or on rollover - just because it doesn't display the address doesn't mean that there isn't one! 在大多数电子邮件客户端中,它将显示名称而不是电子邮件 - 在Outlook或Apple Mail中,它通常会显示名称旁边的电子邮件地址或翻转 - 仅仅因为它不显示地址并不意味着那里不是一个!

Some email services will not let you send from arbitrary addresses (such as gmail), so you may still find the from address itself changes. 某些电子邮件服务不允许您从任意地址(例如gmail)发送,因此您仍可能发现来自地址本身的更改。

You should not try to send without a from address for all the reasons Michael_B gave, plus that it's also very unlikely to work at all; 出于Michael_B给出的所有原因,你不应该试图在没有地址的情况下发送,而且它根本不可能工作; that's why both PHP and PHPMailer add one that's generated automatically from your hostname. 这就是为什么PHP和PHPMailer都会添加一个从主机名自动生成的原因。

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

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