Created
August 22, 2011 08:34
-
-
Save MiLk/1161937 to your computer and use it in GitHub Desktop.
Mass mailer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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("@", "@", $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