The Send()
method of the class returns a Boolean that will be false
if the message is not sent for any reason.
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';
$mail->AddAddress("[email protected]");
$mail->Subject = "assunto";
$mail->Body = "PHPMailer.";
if(!$mail->Send())
{
echo "Erro: " . $mail->ErrorInfo;
}
else
{
echo "E-mail enviado";
}
?>
You can use an infinite Loop to try to send, but this is not a good practice because the application can get stuck in it trying to send unsuccessfully, so I used a for
limiting the number of attempts to 10, each attempt is spaced in 30 seconds.
for($tentativas = 0; $tentativas < 10; $tentativas++){
if($mail->Send())
{
break;
}
sleep(30);
}