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!
$_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.
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?
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.
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
$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);
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
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...?