Skip to content

Instantly share code, notes, and snippets.

@Christobelle
Created November 20, 2012 08:53
Show Gist options
  • Save Christobelle/4116816 to your computer and use it in GitHub Desktop.
Save Christobelle/4116816 to your computer and use it in GitHub Desktop.
foreach loop to put emails to mail_queue for sending later
//create db connection
$dsn = db_connect();
//to select all email addresses from the test db:
$sql = 'select * from db order by id';
//set up for html output table
echo '<table>';
//loop through addresses
foreach ($dsn->query($sql) as $row) {
/***
use the db_options and mail_options here
***/
$mail_queue = new Mail_Queue($db_options, $mail_options);
$from = 'j@c.com';
$to = $row['email_address'];
$moniker = $row['moniker'];
$message = '
<html>
<body>
message in here!
</body>
</html>';
//set up headers for mail_queue
$hdrs = array( 'From' => $from,
'To' => $to,
'Subject' => "Christmas Cribs" );
/********
use Mail_mime() to construct a valid mail
***********/
$mime = new Mail_mime();
$mime->setHTMLBody($message);
$mime->addHTMLImage('resources/fullsetnewindex_600.jpg');
$mime->addHTMLImage('resources/title.gif');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
/********
Finally Put message to queue
*********/
$m = $mail_queue->put($from, $to, $hdrs, $body);
//and output html to browser to see table of emails put to queue and mail_queue output $m
echo '<tr>';
echo "<td>$m</td>";
echo "<td>$moniker</td>";
echo "<td>$to</td>";
echo '</tr>';
}
//close table
echo '</table>';
//close db connection
$dsn = null;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment