4

Is there a way to check for error when sending mail using SwiftMailer version 4? I am not referring to getting a list of recipient emails that got rejected, and I am not talking about just knowing whether send() worked or not.

I am talking about knowing the actual error that took place during the sending process - such as not able to connect to STMP host, incorrect login, etc.

Manto
  • 1,642
  • 1
  • 13
  • 28
  • Possible duplicate of [Swift Mailer - Can't send mail, and can't find error logs](https://stackoverflow.com/questions/19366289/swift-mailer-cant-send-mail-and-cant-find-error-logs) – fracz Jun 17 '17 at 16:41

1 Answers1

-3

Simply check the return code from SwiftMailer's send() or batchSend() commands for a non-zero result. If you get a non-zero result (i.e. TRUE), then it succeeded connecting and authenticating to your SMTP service.

From the documentation:

//Send the message
$numSent = $mailer->send($message);

printf("Sent %d messages\n", $numSent);

// Note that often that only the boolean equivalent of the
//  return value is of concern (zero indicates FALSE) 

if ($mailer->send($message))
{
  echo "Sent\n";
}
else
{
  echo "Failed\n";
}
ybull
  • 1,031
  • 10
  • 17
  • 6
    I am not interested in knowing just whether the mail was sent successfully or not - I want to know WHAT error I am getting. I've updated my question to be more clear. – Manto May 26 '11 at 18:33