Pan Posted October 21, 2012 Posted October 21, 2012 Is there any restriction on sending e-mails using mail() to the same domain that is hosting the script? I'm slowly building my site during my free time and just noticed that my contact form isn't working properly. It spits out no error, but the mail never reaches it's destination. So, I've created the following test file (let's say my domain is "example.com"): <?php error_reporting(E_ALL); $to = "me@example.com"; $subject = "Test Mail"; $message = "Hello world!"; $headers = "From: no-reply@example.com"; echo mail($to, $subject, $message, $headers) ? "The email was sent" : "Fail!"; ?> Playing with this file I discovered that my mail never gets sent only if the recipient I've specified is from my own domain, the same domain which is hosting the script.If I change it to another one (gmail in this case) it works without problems: <?php error_reporting(E_ALL); $to = "me@gmail.com"; $subject = "Test Mail"; $message = "Hello world!"; $headers = "From: no-reply@example.com"; echo mail($to, $subject, $message, $headers) ? "The email was sent" : "Fail!"; ?> What really puzzles me is that this code works flawlessly in another host - and yes, using my domain. I've been using an DNS Round Robin to check out it's pros & cons and I'm able to test both hosts at the same time. Some useful (or not) information:My MX records are pointing directly to Google's records, since I'm using their Tools, and I'm also using an spf.I'm not using any nameservers, but A records only. The round robin has been working like a charm so far and the only problem I've encountered is the mail() one. I don't see how the round robin could have anything to do with this.If you need more info like seeing my DNS records, or how my mail headers looks like when I manage to send them (through the other host/to my gmail account) just ask. P.s.: English isn't my mother tongue, sorry about any weird sounding sentence. Also, I wasn't sure about where post it. Since it looks like a host-restriction, I've chosen this section.
Ice IT Support Posted October 22, 2012 Posted October 22, 2012 Is the mail for the domain with errors hosted by HelioHost or Google Apps?
Pan Posted October 22, 2012 Author Posted October 22, 2012 Google. And as I've said, the script works with other server, so, in this case it's not Google's fault, I'm even using SPF for my domain.
Ice IT Support Posted October 22, 2012 Posted October 22, 2012 I think this may be an issue on HelioHost's end, probably caused by your DNS configuration. This isn't your fault, HelioHost's configuration tends to be picky about DNS. It's not typical for a domain to have more than one A record. @admins: Thoughts? Anything I may be missing?
Krydos Posted October 22, 2012 Posted October 22, 2012 I'm guessing this is you? 2012-10-21 10:41:12 1TPzWk-0004Nh-EZ ** c****a@v******d.com.br: Unrouteable address The problem is that the way you have it set up when you send an email to your own domain the server tries to send that email to itself, but then that email address hasn't been created through cPanel so it just gives an error and nothing gets sent.
Ice IT Support Posted October 22, 2012 Posted October 22, 2012 The domain has MX records configured correctly, why would that be the problem? Unless the user/email was not created in Google Apps.
Pan Posted October 22, 2012 Author Posted October 22, 2012 Yup, that's me. I've set up this mail through Google Apps years ago.
Krydos Posted October 22, 2012 Posted October 22, 2012 Is there any restriction on sending e-mails using mail() to the same domain that is hosting the script?No, there isn't. I copy/pasted your code exactly changing the email addresses to match the account I was testing it on and it worked just fine.
Pan Posted October 23, 2012 Author Posted October 23, 2012 Thanks for the replies, they gave me a hint of what do... It was a really silly fix and I hope this reply help people in the future. I had to visit my MX Records on CPanel and set it manually to "Remote Mail Exchanger". I've also made sure that there were no MX Records there for my domain. I took this as an opportunity to explore the Mail-related sections and I've set up my gmail address as Default Address in case of fails. I've also explored my account's webmail, before I avoided it thinking it would only work if I had my domain's e-mails set there, what isn't true.It was a happy discovery, it was full of "Mail delivery Failed" messages reporting the "Unroutable Address" problem, haha, if only I knew it before I wouldn't need to bother you. Now I know where to look for info when e-mailing fails. Problem solved. ^^
Recommended Posts