Skip to content

Instantly share code, notes, and snippets.

@MiLk
Created August 22, 2011 08:34
Show Gist options
  • Save MiLk/1161937 to your computer and use it in GitHub Desktop.
Save MiLk/1161937 to your computer and use it in GitHub Desktop.
Mass mailer
<?php
/*
* Mass mailer with PHPMailer
* http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/PHPMailer_v5.1.zip/download
*/
require_once('./class.phpmailer.php');
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$body = file_get_contents('contents.html'); // HTML file to make content
$body = eregi_replace("[\]",'',$body);
$mail->SetFrom('email adress', 'name');
$mail->Subject = 'Subject';
@MYSQL_CONNECT("","","");
@mysql_select_db("");
$query = 'SELECT DISTINCT(email) FROM adresses WHERE send=0';
$result = @MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result)) {
$mail->MsgHTML($body);
$email = $row['email'];
$mail->AddAddress($email,$email);
if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("@", "&#64;", $email) . ') ' . $mail->ErrorInfo . '<br>'."\r\n";
mysql_query('DELETE FROM adresses WHERE email LIKE "'.mysql_real_escape_String($email).'"');
} else {
echo "Message sent to :" . $email . '<br>'."\r\n";
mysql_query('UPDATE adresses SET send=1 WHERE email LIKE "'.mysql_real_escape_string($email).'"');
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment