0

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.

Sithu
  • 4,752
  • 9
  • 64
  • 110
  • Sounds like you are using a mail provider that alters your messages. Which is illegal in most countries for good reasons. I suggest you change the provider. – arkascha Feb 07 '14 at 10:10
  • @arkascha, mail provider? I'm using the local XAMPP server in my PC that was mentioned in my question. – Sithu Feb 07 '14 at 14:18
  • And what SMTP server do you use to send a mail message? Or do you think somehow the http server suddenly knows how to speak email protocols? – arkascha Feb 07 '14 at 14:26
  • Settings in php.ini is `SMTP = localhost` `smtp_port = 25` – Sithu Feb 08 '14 at 03:27
  • OK, so you yourself are the mail provider who alters your messages. So I would like to alter my suggestion: instead of changing the provider, change the configuration of your mail server! Certainly it _is_ possible to configure a server such that you can send out messages with such a non-existing from address. You answer you gave below is a workaround, but not a solution of the problem. – arkascha Feb 08 '14 at 08:35
  • BTW: a typical step in trying to find the cause of such problems is to take a look in to the (mail) servers log files. Maybe you have to raise the logging level. It should tell you why it alters and give a hint what you have to change. – arkascha Feb 08 '14 at 08:37
  • And another btw: just to be really sure, since it just dawned to me: are you really sure that the messages get sent _at all_? And that it is not just messages being returned to the from address because they cannot be delivered? That would explain why you do not receive back those massages with a non-existing from address... – arkascha Feb 08 '14 at 08:39

3 Answers3

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.

Maarkoize
  • 2,601
  • 2
  • 16
  • 34
  • I'm using the local XAMPP server in my PC that was mentioned in my question. `localhost.com` means `127.0.0.1` which is a local server. XAMPP is a web server including Apache, PHP, MySQL and Mercury which is an installer for a PC machine. When you install XAMPP in your machine, you can run `http://localhost` in your browser and you are available to use a mail server of `SMTP_HOST = localhost`. – Sithu Feb 07 '14 at 14:24
  • Yes I know. And that's the problem, because you send it via Mercury Mail from a local PC. That mails will be rejected by most providers. – Maarkoize Feb 07 '14 at 14:29
  • I'm testing in localhost from one local mail to another local mail. I know that sending a local mail to online mail providers does not work. – Sithu Feb 07 '14 at 14:41
0

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

  • I think `Sender Name` without quotes should be working according to the php documentation. The No 2 without `Sender Name` mentioned in my question does not work as well. Anyway, I will try it. – Sithu Feb 07 '14 at 14:42
0

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.

Sithu
  • 4,752
  • 9
  • 64
  • 110