So I've got a php script that emails me a daily database backup via cron. The script will either output success or failure upon mail->send(), and it always succeeds. However, no email ever is delived if the domain name is the same (i.e. www.example.com and myself@example.com), but if I send to another domain such as myself@gmail.com then the script works fine. Obviously, a solution would be to just email myself@gmail.com, but I'm trying to understand why I can't send emails to @example.com.

Note: It will send emails to @example.com when run from the browser. What could suppress emails to @example.com from cron and not the browser?

Is the e-mail for domain hosted on the same server which is sending you the e-mail? If it isn't, you'll probably find that you have a setting which lists that domain as a local domain, meaning any mail sent through or from your server to that domain will be delivered locally. If the mail isn't on that server, the message bounces. The mail sending script will still report success though.

I suggest you check your mail logs on your server to see if the messages are bouncing when sending to your domain in any case. This will tell you the reason why messages aren't getting through. The fact you mentioned Cron makes be presume this is hosted on Linux. If this is the case, the default mail log location is /var/log/maillog but it may be different on your server depending on your configuration.

Thanks for the suggestion Borzoi! My web host provides my email hosting as well, so I assume they are on the same server. Unfortunately, I don't have access to mail logs from my web host. But maybe they will be able to look at them for me.

A lot of web hosts will have the e-mail and websites on seperate servers. Even if that is the case, the mail logs will still be useful in determining the cause of the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.