Answer the question
In order to leave comments, you need to log in
Why is a letter sent in a cycle 2 times to one addressee (loop iteration sticks)?
Hello. I can’t understand anything, why some iterations are performed twice, written twice to the database and letters sent twice. I would also like to disconnect every 30 letters, for this I used $mail->SmtpClose(); in PHPMailer, but then something strange happens, the records in the database appear out of order (!), That is, not 1 2 3, but 1 3 2. Can anyone show the reason for this behavior? And how to do it all the same, so that letters would be sent 1 time, between each sending there was a pause of a second, and after 30 letters the connection was broken and there was a pause of 10 seconds and everything over again ..
I experimented many times, but did not achieve a meaningful result ...
<?php
$identNumber = 0;
// Generate UUID v4 function - needed to generate a CID when one isn't available
function gaGenUUID() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
foreach ($mails as $sendMail) {
$gcid = gaGenUUID();
$mailadressant = $sendMail;
$message = $mailtemplate;
$mail->ClearAllRecipients();
$mail->ClearCustomHeaders();
$mail->setFrom('[email protected]', 'From mail');
$mail->addReplyTo('[email protected]', 'From mail');
$mail->Subject = "Тема письма";
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->Body = $message;
$mail->AltBody = $message;
$mail->addAddress($mailadressant); // Add a recipient
$mail->addCustomHeader('List-Unsubscribe', 'http://mail.ru/uns.php');
if (!$mail->send()) {
$maillogstatus = 'Mailer Error: ' . $mail->ErrorInfo;
} else {
$maillogstatus = "ok";
}
sleep(1);
$sendQuery = ('INSERT INTO mail_log ( log, maillogstatus ) VALUES( ?, ? )');
$params = array( $mailadressant, $maillogstatus);
insertDB($sendQuery, $params);
if ($identNumber % 30 == 0) {
//$mail->SmtpClose();
sleep(10);
}
$identNumber = $identNumber + 1;
}
echo "done";
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question