0

OK, so I have a PHP mail function. It works fine when I put it on my server but when I put I mail it to my client so he can put it on his server it doesn't work. It doesn't give me any errors on their server and gets to the "Thanks" page just fine but never really sends the email. They say it's because PHP Mail does not have the right headers but I didn't think that it needed headers if it was just simply "mail(to, subject, message)" They say they have all PHP related functions set properly because I initially thought it was PHP Mail being turned off.

Any suggestions would be great.

Howdy_McGee
  • 10,422
  • 29
  • 111
  • 186
  • maybe you are missing the PHP libraries that you need for your function calls on the clients you are sharing your software with. – Bnjmn Aug 08 '11 at 20:23
  • Does the call to the mail function return `true` when called on the client's server? – K4emic Aug 08 '11 at 20:25
  • use the basic method like: mail("to_my_email@mail.com", "subject", "message", "FROM: my-email-from@mail.com"); – Adnan Aug 08 '11 at 20:26
  • Adnan, I tried that and still no luck. – Howdy_McGee Aug 08 '11 at 20:28
  • Who is your client using for hosting? If its a company like GoDaddy then you will only be able to "send" from an "authorized" email address and this likes to bite you in PHP as the mail method will return true even though the email itself didn't go through. – jdarling Aug 08 '11 at 21:17

4 Answers4

3

PHP's mail function is a piece of garbage. If it says true, it only means the email was handed off from PHP to the local mailserver. It does NOT mean the email was actually delivered. In real world terms, mail() stuffs your envelope into the mailbox on the corner, then starts proudly saying "I did it! I delivered it to your user!"... with the envelope still stuck inside the mailbox.

Your client should check his mail server's logs to see what's happening with the email once it's handed off from PHP. Even if the mail itself gets bounced or spam-trashed later, PHP's mail function will NEVER see any of those errors.

Marc B
  • 356,200
  • 43
  • 426
  • 500
2

You should always be using a "FROM" header.

Note:

When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

This is straight from the documentation for mail()

Jared
  • 12,406
  • 1
  • 35
  • 39
  • 1
    Okay, is this a production environment? Is display_errors turned on? Have you checked the junk mail? – Jared Aug 08 '11 at 20:28
  • :S it's in my junk mail, why? This doesn't usually happen. – Howdy_McGee Aug 08 '11 at 20:30
  • Headers is a possible reason but check out this link http://stackoverflow.com/questions/371/how-do-you-make-sure-email-you-send-programmatically-is-not-automatically-marked – Jared Aug 08 '11 at 20:33
  • Yeah when I send it - it has this weird "via server1.example.notmydomain.com" which I've never seen before. Could that be the reason? – Howdy_McGee Aug 08 '11 at 20:36
0

In my experience, I've almost always had better luck setting up a dedicated mail account for the client in their domain on their mail server and authenticating with the mail server and sending mail through it using SMTP via PEAR_Mail. You'll get much more useful information from PEAR_Mail if something goes wrong in the sending process, plus by sending via SMTP via the mail server you have a better chance of avoiding issues with SPF, etc.

Jeremy Clifton
  • 533
  • 5
  • 17
0

Make sure a mail transport agent, such as sendmail is installed on the server.

Gerry
  • 10,584
  • 4
  • 41
  • 49
  • 1
    BTW, I agree with everybody here who has said that mail() sucks. I use swiftmailer instead: http://swiftmailer.org/ – Gerry Aug 08 '11 at 20:46