问题
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:
- From: Sender Name
<noreply@localhost.com>
- From:
noreply@localhost.com
- 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