PHP mail function reporting mail sent but mail never receive

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clem_c_rock
Forum Commoner
Posts: 46
Joined: Mon Jun 07, 2004 9:18 am

PHP mail function reporting mail sent but mail never receive

Post by clem_c_rock »

Hello,
I have a script that suddenly stopped working and nothing's been changed. I am using the php mail() function to send a simple email form and the mail() function report true when it is fired off but I can never receive the emails.

I suspect something's changed in our hosting but wanted to rule everything out before I started investigating there.

Here's the simple code I am using:

Code: Select all

 
      $send_tenant_mail = mail( $tenant_email, $subject, $body_header, "From: $from\nReply-To: $from\n" );
          if($send_tenant_mail == 1)
      { 
          $confirm = "A Confirmation Email has been sent to: $tenant_email";
      }
 

Thanks,
Clem C
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: PHP mail function reporting mail sent but mail never receive

Post by infolock »

Try this instead:

Code: Select all

 
if(false == mail( $tenant_email, $subject, $body_header, "From: $from\r\nReply-To: $from\r\n" )) {
  echo "FAILED TO SEND!";
  exit;
}
 

Notice \r\n is used...


If no "FAILED TO SEND" is seen, then this can be 1 of a few issues, none are a result of PHP failure though...

1) Mail server could have a huge que and your message you are trying to send out hasn't been gotten to.

2) An email in the server has hung and the server is trying to infinately send it back out (iow, no one set a max retry)

3) the server connection has failed.

4) there is other issues with the mail server

5) check your spam box, might have ended up there.


I am making a huge assumption here and assuming you have access to the server's terminal and it's running linux with mail installed. try sending an email from command prompt. otherwise, the server may not be accepting emails from the account you are trying to send from (ie www) or another configuration is needed.


short answer: check mail server or spam box


hope this helps.
Post Reply