tags:

views:

1478

answers:

6

Hey,

I'm not sure I'm using all the correct terminology here so be forgiving.

I just put up a site with a contact form that sends an email using the PHP mail() function. Simple enough. However the live site doesn't actually send the email, the test site does. So it's not my code.

It's a shared host and we have another site that has the same function that works perfectly, so it's not the server.

The only difference between the two is that the site that doesn't work just has the name server pointing to us and so the MX record never touches our server.

So my question is, could some one please confirm that the mail() function wont work if we don't have the MX record pointing to our server. Thanks

+1  A: 

Yes, you could put in what ever you want in the 'from' field and it would still work.

paan
+3  A: 

Yes. It will work just fine. I have a PHP script using the mail() function with the MX records set to Google Apps.

If the two scripts are on different hosts (it's a bit unclear from your post), then make sure that the host doesn't block some of the custom headers. I had issues with this when creating my script, but removing all but the From header fixed the problem.

Dan Walker
+2  A: 

Some hosts (Godaddy is the worst) block your use of sendmail and mail().

I generally use smtp to send emails from my php applications and with PHPMailer it's super easy. Many applications are using older versions of PHPMailer and sometimes updating it can help. It's also easy enough to add quickly to short scripts as well.

Eric Goodwin
+1  A: 

The mail() function sends mail from the server hosting the script. Since many shared hosting providers host separate mail servers, and because the mail() function doesn't support any sort of authentication, many shared hosting providers block it.

+1  A: 

If the site uses SPF, remember to include the sending site in your SPF record. For more info see here.

Brian Rasmussen
A: 

Hey guys thanks for the answers, it is really appreciated.

After ignoring the issue for a few months it has come up again, I did however find the answer to my problems.

Firstly, as you answers suggested, PHP and the mail() function were working as expected. The mail was getting sent.

The problem lies when the email is sent, it simply presumes that because its being sent from mydomain.com to *@mydomain.com email that the email itself is hosted on the same server, so it gets sent there instead and ignores the MX record.

OK it's a bit more complicated than that, but that is the general jist.

Edit: Found a better version of the topic http://stackoverflow.com/questions/322659/sendmail-and-mx-records-when-mail-server-is-not-on-web-host.

cole