Reputation: 279
trying to send more than 2000 mails by fetching email id from Database, actually 240 mails sent successfully , after that i got some error like this
code
$mail->addAttachment('images/attach.gif');
$mysql = mysql_connect('localhost', 'username', 'password');
mysql_select_db('db_name', $mysql);
$result1 = mysql_query("SELECT first_name, email_id FROM email WHERE status = '0'", $mysql);
$body = file_get_contents('contents.php');
while ($row1 = mysql_fetch_array($result1)) {
$mail->AltBody = 'alt body text here';
$mail->msgHTML($body);
$mail->addAddress($row1['email_id'], $row1['first_name']);
if (!$mail->send())
{
echo "Mailer Error (" . str_replace("@", "@", $row1["email_id"]) . ') ' . $mail->ErrorInfo . '<br />';
break; //Abandon sending
} else
{
echo "Message sent to :" . $row1['first_name'] . ' (' . str_replace("@", "@", $row1['email_id']) . ')<br />';
}
// Clear all addresses and attachments for next loop
$mail->clearAddresses();
$mail->clearAttachments();
}
after 240+ mail sent i got this kind if errors , i m new to phpmailer please tell me what is the problem and how to fix this problem, the bug
error
Mailer Error (***email***) The following From address failed: [email protected] : MAIL FROM command failed,503,sender already given
Mailer Error (***email***) The following From address failed: [email protected] : MAIL FROM command failed,503,sender already given
Mailer Error (***email***) SMTP Error: data not accepted.
Mailer Error (***email***) The following From address failed: [email protected] : MAIL FROM command failed,503,sender already given
Mailer Error (***email***) The following From address failed: [email protected] : MAIL FROM command failed,503,sender already given
...
...
...
Upvotes: 1
Views: 1527
Reputation: 37770
Make sure you're using latest PHPMailer. msgHTML()
also sets AltBody
, so if you want a custom AltBody
, set it after the call to msgHTML
.
The MAIL FROM
errors suggest you may not be completing a previous message, which could be due to misformatted content or a message count limit during a single session. If you enable debugging with $mail->SMTPDebug = 2;
, you'll be able to see more of the conversation.
Try setting $mail->SMTPKeepAlive = false;
to make it send each message separately (which is slower but more reliable), as this may be because you are trying to send more messages in a single connection than your host allows. You could make your send loop close and reopen the SMTP connection every 200 messages to avoid this issue.
Upvotes: 1