From address is not working for PHP mail headers

我的未来我决定 提交于 2019-12-12 01:11:45

问题


I'm sending "no-reply" mails using PHP mail function. The problem is that mails were sent, but not receiving in my inbox when I use the following "From" headers:

  1. From: Sender Name <noreply@localhost.com>
  2. From: noreply@localhost.com
  3. From: Sender Name <test@localhost.com>

I have no actual mail address noreply@localhost.com, but I have test@localhost.com.
I think all of them are the correct formats according to the PHP documentation.

When I tried From: test@localhost.com, it did work and I received the mail.
I really want to use the No. 1 format Form: My Site Name <noreply@localhost.com>. It should work. Any idea?

I'm using XAMPP 1.6.7 with PHP 5.2.6 and MercuryMail.


回答1:


Emails send by a private mail server and dynamic ip's are rejected by the most email providers to prevent spam. Seems like your provider is one of these.

You can take a look for a provider which gives you a smtp-relay server, but maybe it's not possible to change the "From"-adress then. That depends on the provider.

The other possibility is to create an account by an email provider (for example gmail) and use the SMTP server given by the email provider. But then you can't change the "From" address, too.




回答2:


Try to put Sender Name in the quotes: "Sender Name"




回答3:


Eventually, I received the mails using Sender Name <noreply@localhost.com> by doing the following:

(1) I had to remove the comment for sendmail_path in php.ini to use sendmail.exe

sendmail_path = "D:\xampp\sendmail\sendmail.exe -t"

(2) Then, I had to create an account noreply@localhost.com in my local MercuryMail server.

Otherwise, mails were sent, but not received in my inbox.



来源:https://stackoverflow.com/questions/21624773/from-address-is-not-working-for-php-mail-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!