我一直有問題使用phpmailer發送批量電子郵件,雖然沒有一個電子郵件的問題。如何發送電子郵件到從其他數據庫中獲取數據庫的電子郵件列表
這裏是我的代碼:
$result = mysql_query("select * from $to",$conn) or die("list
selected ($to) does not exist ".mysql_error());
while ($row = mysql_fetch_array($result))
{
$email[] = $row['email'];
$student[] = $row['name'];
}
foreach ($email as $val => $uemail) {
$email = $uemail;
$students= $student[$val] ;
require("class.phpmailer.php");
$mail = new PHPMailer(true);
try {
$mail->AddReplyTo('[email protected]', 'My Name');
$mail->AddAddress("$email", "$student");
$mail->SetFrom('[email protected]', 'MyName');
$mail->AddReplyTo('[email protected]', 'My nameg');
$mail->Subject = "$sub";
$mail->MsgHTML("Dear $student<br> $msg <br>
<img src=\"$path\"> <p>
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE.
***DO NOT RESPOND TO THIS EMAIL****
");
$mail->AddAttachment("$path2"); // attachment
$mail->Send();
echo "Message Sent OK to $email </p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
任何幫助,建議將不勝感激。
謝謝。完善 – kplus