I am trying to send rich email to people on a mailing list and am running into trouble getting the rich email part to work. My code says all recipients have been sent an email, but the email is not received.
Here is what I have:
#assemble mail headers#############################
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From:$admin_email\r\n";
$headers .= "Reply-To:$admin_email\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
##################################################
#connect to database and retreive email addresses
$db = mysql_connect("localhost", "username", "password") or die("Could not connect to the database.");
mysql_select_db("mydbname",$db) or die(mysql_error());
$query = "SELECT * FROM mailing_list";
$result = mysql_query($query,$db);
#determine how many people are on the list for later comparison with successful emails
$num_members = mysql_num_rows($query);
$num_success = 0; #init variable to track the number of successfully sent emails
$failure = ""; #var to be used to track all email failures
do{
$ok = mail($mailarray['email'], $subject,$letter,$headers);
if($ok){
sleep(5); #pause for 5 seconds between emails to avoid flooding the mail server
$num_success++;
}else{
$failure .= "Email could not be sent to ".$mailarray['email']."\n"; #record failures
}
} while ($myrow = mysql_fetch_array($result));
#if all went well, store a success message
if(empty($failure)) $failure = "There are no failure messages to report";
#when loop is done, send email to administrator with results of process
if(mail($admin_email,"Newsletter Send Results","Your newsletter has been sent. Below are the results of the send process:
Number of Recipients: $num_members
Number of Successful Emails Sent: $num_success
Failure Messages: $failure")){
echo "The newsletter sending porcess is complete!<br />
An email has been sent to ".$admin_email." with the results of the newsletter sending process.";
}
Ideally I would like to be able to send a multipart email that will deliver plain text or HTMl versions of the message, but will settle for a working HMTL based email.