Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/119613-returned-emails-problem/
Share on other sites

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!

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

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? :(

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.