Page 1 of 1

mail() and delivery error not receiving

Posted: Sat Jul 25, 2009 4:11 pm
by korner
Hello,
can someone help me please. I am sending an email like this:

Code: Select all

 
$_headers = "From: $_email";
mail('notExistingEmail@existingDomain', 'testing', 'this is test', $_headers);
 
in $_email is my existing email. I am sending this email to an email that does not exist on that domain. So when I try to send mail using my normal account (etc. gmail, yahoo) not via php I receive to $_email error notification that this email doesn't exist on that domain. That's OK and proof that this mail really don't exist. But when I send it via php script as listed above I don't receive this notification. I am sending it to one existing mail too so I know that mail() is sending emails. Am I missing something in my headers?
thanks.

Re: mail() and delivery error not receiving

Posted: Sat Jul 25, 2009 8:26 pm
by jackpf
mail() doesn't check if the email has been sent; it just sends it.

If you want to check if the email address exists, you can use something like checkdnsrr($email, 'MX').

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 2:26 am
by korner
Please read my whole questiong before answering :)
I am not trying to check if mail was delivered using mail() function. My problem is that when I send mail to not existing mail NOT with php script (using etc. gmail) I become a delivery failure mail from the mail server. But when I send mail with php script via mail() function the delivery failure is not returned to my email. Does gmail insert something to headers that I am missing? I used the same headers as gmail and it is not working. why?

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 7:59 am
by jackpf
Well, if you read my post before replying, you'll see that mail() doesn't check if the email has been sent.

If you want to check for sending errors then you'll have to either use a mail script, or write your own using sockets, like I've done here, and use something like mx record checking.

This is my understanding of the subject.

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 8:10 am
by Eric!
korner wrote:Does gmail insert something to headers that I am missing? I used the same headers as gmail and it is not working. why?
I doubt you are using the full headers that gmail is using. I don't see a reply-to field or a return path. You should receive the bounced email message if it was undeliverable. Most mail servers will deliver this to the reply-to address. There are some servers which are configured differently though....

At a bare minimum, this is how I would do it with php

Code: Select all

 
  $from_name="First Last";
  $from="me@my.domain";
  //Build the email header            
  $eol="\r\n";    
  $headers = "Reply-To: ".$from_name."<".$from.">".$eol;
  $headers.= "From: ".$from_name."<".$from.">".$eol;
  $headers.= "Content-type:   text/plain".$eol;
  $headers.= "Message-ID: <".time()."-".$from.">".$eol;
 
  // SEND THE EMAIL
  $to="you@your.domain";
  ini_set(sendmail_from,$from);  // the INI lines are to force the From Address to be used !  
  $returnpath="-f ".$from;  // Forces the return path to be configured properly   
  $mail_sent = mail($to, $subject, $content, $headers, $returnpath);

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 9:54 am
by jackpf
Hey :)

But surely that won't tell you if you've sent mail to a non-existent domain, only a non-existent email address of an existing domain?

So I still reckon you need mx record checking as well.

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 10:15 am
by Eric!
No, you're right, the php mail() doesn't tell you crap. But I think he is looking for the bounced email error message that comes back to his inbox....

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 10:22 am
by jackpf
Oh right.

Fair enough...but fyi, I did read your post, I just misunderstood...there's no need to be rude when I'm actually trying to help you.

Besides, you should do what I said anyway...as it doesn't rely on the recipient's server having a bounceback system.

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 10:32 am
by korner
ok jackpdf I really appreciate that you are trying to help, but Eric!s' answer what I was looking for. But in my case it didn't worked because I can't change my safe_mode settings and it's saying that in safe mode I cannot insert the fifth parameter even when I try to turn off the safe_mode (it's not my server and I cannot change that setting:( ) but I searched in the source code of the email it is sending and there is something like this:
X-Authentication-Warning: web2s18.XXX.XX: apache set sender to webmaster@XXX.XX using -f
so I created mail webmaster@... and realy there are my delivery failure emails :(, so my only solution is that I am forwarding messages from webmaster@.. to my email.
thanks to all :drunk:

Re: mail() and delivery error not receiving

Posted: Sun Jul 26, 2009 10:42 am
by Eric!
korner wrote:I searched in the source code of the email it is sending and there is something like this:
X-Authentication-Warning: web2s18.XXX.XX: apache set sender to webmaster@XXX.XX using -f
I don't know why your host would do this. This means that if you have more than one email user on your site that all the errors are going to go to the webmaster and not the originating address. Perhaps there is a user configurable setting somewhere to direct errors back to the reply-to address like most servers...?