ballouta Posted August 14, 2008 Share Posted August 14, 2008 Hello I have the following piece of code to send an HTML email. I am intending to send a message to non exisiting email address (igfdgfdgdfg@ffgsdfddddddfdfdfgdf.com) When I sent a message from my webmail using the 'Horde', a delivery failure message comes quickly (good). When I used my script, the delivery failure doesn't come (bad). Note that I need these returned messages inorder to run a script and remove the invalid ones from my DB. Also note that the no-reply email really exists. here's my code: <?php //define the receiver of the email $to = 'igfdgfdgdfg@ffgsdfddddddfdfdfgdf.com'; //define the subject of the email $subject = 'Test HTML email'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: Arab eMarketing\r\nReply-To: no-reply@mysite.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="windows-1256" Content-Transfer-Encoding: 7bit <h1 dir="ltr">Name: Ballout Name</h1> <h2 dir="ltr">Age: 30 to</h2> <h3 dir="ltr">BYE</h3> --PHP-alt-<?php echo $random_hash; ?>-- <? //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> thank You Quote Link to comment https://forums.phpfreaks.com/topic/119613-returned-emails-problem/ Share on other sites More sharing options...
Rohan Shenoy Posted August 14, 2008 Share Posted August 14, 2008 You can't do that PHP mail() function because it just 'packages' the mail for delivery and then sends it out. It returns TRUE or FALSE depending upon whether it was able to send it out or not. The mail() function cannot check if the mail reached the recipient's inbox! Quote Link to comment https://forums.phpfreaks.com/topic/119613-returned-emails-problem/#findComment-616245 Share on other sites More sharing options...
toplay Posted August 14, 2008 Share Posted August 14, 2008 if you're using the mail() function, then do not send your own headers as you show, but rather set any appropriate settings in $headers and pass it as the fourth argument to the mail() function. http://us3.php.net/manual/en/function.mail.php Also, look into using something like PHP Mailer: http://sourceforge.net/projects/phpmailer and their home page/tutorial: http://phpmailer.codeworxtech.com/index.php?pg=tutorial Quote Link to comment https://forums.phpfreaks.com/topic/119613-returned-emails-problem/#findComment-616246 Share on other sites More sharing options...
ballouta Posted August 14, 2008 Author Share Posted August 14, 2008 Hi Rohan, of course the returned messages will be processed via a php scrip using IMAP functions, or at least let the returned emails come to my webmail. Hi toplay, I will check the two links before doing anything. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/119613-returned-emails-problem/#findComment-616247 Share on other sites More sharing options...
ballouta Posted August 14, 2008 Author Share Posted August 14, 2008 hi again I tested three examples shown in fucntion.mail.php link I also tried the phpmailer, it is really great. both has sent the message successfully to my valid email address. But when i sent a message to non exisiting email, i didn't get any returned email in all test. Why? Quote Link to comment https://forums.phpfreaks.com/topic/119613-returned-emails-problem/#findComment-616258 Share on other sites More sharing options...
JonnoTheDev Posted August 14, 2008 Share Posted August 14, 2008 This is really simple. PHP does not send mail as a user on the mail server. Obviously you set the from address in your code but the email will be sent from nobody. Therefore any bounced messages will usually end up in the server admins email. You can define this address in your httpd.conf if using apache I think. If you want to find out if a message has not been sent correctly then you will need to write a program that can parse your servers mail logs (usually /var/log/maillog). This is usually the approach if lets say you were making a newsletter system that sends messages to your website members. You want to get rid of the members that messages do not get through to i.e. dead or non existent email addresses otherwise you may get blacklisted as a spammer for sending emails to non-existent email addresses all the time. Quote Link to comment https://forums.phpfreaks.com/topic/119613-returned-emails-problem/#findComment-616368 Share on other sites More sharing options...
ballouta Posted August 14, 2008 Author Share Posted August 14, 2008 hi neil i am sure that you got my idea 100% I thought it is very easy thing, I didn't expect this but is nice to work on it and do my best. thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/119613-returned-emails-problem/#findComment-616843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.