<?php
$mail_subject='blahblahblah';
$mail_body='Yadda yadda yadda';
$db_connection = mysql_connect($dbhost, $dbuser, $dbpass);
$db_select = mysql_select_db($dbname);
$q = mysql_query("select email, name from table");
while($r=mysql_fetch_assoc($q)){
$email = $mail_body;
if(!empty($r['name'])){
$email = 'hi there ' . $r['name'] ."\n\n" . $mail_body;
}
send_email($to_email, $r['email'], $mail_subject);
}
function send_email($to_email, $email, $subject){
$domain='mysite.co.uk';
$our_email_name = 'NO REPLY '.$domain;
$our_email = 'NO_REPLY@'.$domain;
$email = '<font face="arial">' . $email . '</font>';
$headers = "From: $our_email_name<$our_email>" . "\n";
$headers .= "Reply-To: $our_email\n";
$headers .= "Return-Path: $our_email\n"; // these two to set reply address
$headers .= "Message-ID: <".time()."@$domain>"."\n";
$headers .= "X-Mailer: EdmondsCommerce Mailer Function"."\n"; // These two to help avoid spam-filters
$headers .= "Date: ".date("r")."\n";
$headers .= "MIME-Version: 1.0" ."\n";
$headers .= "Content-type: text/html; charset=us-ascii" . "\n";
mail($to_email,$subject,$email, $headers, '-f ' . $our_email) or die ('<h3 style="color: red;">Mail Failed</h3>');
}
?>