So I have this function:
$toAddress = $sendTo;
try {
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = self::$host;
$mail->Port = 587;//self::$port; // or 587
$mail->SMTPSecure = 'tls';
$mail->IsHTML(true);
$mail->CharSet = self::$charset;
$mail->Username = self::$username;
$mail->Password = self::$password;
$mail->SetFrom(self::$from, self::$fromAlias);
$mail->Subject = trim("Here's your csv.");
$mail->Body = trim("Thank you for using List Master Application. Please download your csv on this link. <a href='http://36.55.238.182:81/pagination/download?file=".$fileName."'>Here!</a>");
if(is_array($toAddress))
{
foreach($toAddress as $to_line)
{
$mail->AddAddress($to_line);
}
}
else
{
$mail->AddAddress($toAddress);
}
if ($mail->send())
{
log_message('debug', 'sucessfully send email to ' . $sendTo);
return TRUE;
}
else
{
log_message('debug', 'Failed to send email to ' . $sendTo);
log_message('debug', 'Failed message is : ' . $mail->ErrorInfo);
return FALSE;
}
} catch (phpmailerException $e) {
log_message('debug', $e->errorMessage()); //Pretty error messages from PHPMailer
} catch (Exception $e) {
log_message('debug', $e->getMessage()); //Boring error messages from anything else!
}
I have been told previously that I need to upgrade the PhpMailer.
But I need to know why does it sometimes send successfully, and also it sometimes fail in this phpmailer 5.2 version.
Could there be any mail() settings missing?
Is there any reason for it to time-out?
Could it be that server mail regarded it as spam mail?
It's good that mostly it sends successfully but when it fails, I check the log and it gives me this:
The following From address failed: [email protected] : Called Mail() without being connected
Why is this showing when email fails to send?
What does this mean?
true
to the constructor), your try/catch will do nothing. - Synchro