7

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

4

6 回答 6

3

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.

于 2008-09-02T01:24:33.993 回答
2

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.

于 2008-09-02T14:33:26.017 回答
2

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 sendmail and MX records when mail server is not on web host.

于 2009-02-24T01:09:17.330 回答
1

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.

于 2009-01-11T12:05:05.850 回答
1

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

于 2009-01-11T12:51:43.290 回答
0

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

于 2008-09-02T01:15:42.360 回答