電子メール キューを実行して電子メールを送信する PHP foreach ループがあります。私の問題は、キューのすべての行のキューからすべてのメールにメールを送信することです。キューに50通のメールがあるとしましょう。50通のメールが届きます。クールではありません
foreach は次のとおりです。
$cue = new NewsletterHandler;
$cue->GetEmailCue($letter_id, $lhash);
require_once(INCLUDE_DIR."/class.phpmailer.php");
$mail = new PHPMailer();
$mail->From = "tegl@xxxxxxx";
$mail->FromName = "Randers Tegl";
$mail->Host = "smtp.xxxxx.dk";
$mail->Mailer = "smtp";
foreach($cue->email_row as $key => $value) {
$mail->AddAddress($value);
$mail->Subject = $subject ." - ". date("d-m-Y");
$mail->Body = $this->htmlTemplate;
if(!$mail->Send()) {
echo "E-mailen er ikke sendt til ". $value;
echo "Mailer Error: ". $mail->ErrorInfo;
echo "<br />";
mail("morten@domain.dk", "Error", "Letter not send. ". $mail->ErrorInfo ."");
} else {
$sql_update = "UPDATE newsletter_emailcue SET time_recieved = NOW() WHERE email = '". $value ."'";
SQLHandling::SQLquery($sql_update);
echo "Newsletter send to ". $value ."<br />";
}
}
GetEmailCue 関数:
function GetEmailCue($letter_id, $lhash) {
$sql = "SELECT * FROM newsletter_emailcue WHERE mail_to_recieve = '". $letter_id ."' AND time_recieved = '0000-00-00 00:00:00' LIMIT 50";
$result = SQLHandling::SQLquery($sql);
if(mysql_num_rows($result) < 1) {
Main::txtOutput("Der er ikke nogle modtagere til nyhedsbrevet", "TXT_ERR");
/*** If there aren't any emails in the cue table, but a pending letter was found
* that letter will be updated with '2' in status, which is send completed.
*/
$sql_update = "UPDATE newsletter_items SET status = 2 WHERE letter_id = '". $letter_id ."'";
SQLHandling::SQLquery($sql_update);
} else {
while($row = mysql_fetch_array($result)) {
$this->email_row[] = $row["email"];
}
}
return $this->email_row;
}
もし私が手に入れるなら、私var_dump($cue->email_row) outside the foreach
は手array(2) { [0]=> string(17) "morten@domain1.dk" [1]=> string(14) "morten@domain2.dk" }
に入れます
array(2) { [0]=> string(17) "morten@adomain1.dk" [1]=> string(14) "morten@domain2.dk" }
array(2) { [0]=> string(17) "morten@domain1.dk" [1]=> string(14) "morten@domain2.dk" }