I'm sending email using the following code:

$mail =& JFactory::getMailer();
$email_sent = $mail->sendMail( 
        $reply_to_name );
if($email_sent) {
    echo "Mail sent.";
} else {
    echo "Mail NOT sent.";

All of the variables are set to the appropriate values.

When $email_sent is false, is there a way to capture the error message or another way to find out why the email wasn't sent?

I'm on Joomla 3.7 and php 5.6.

3 Answers 3


Firstly, just on a side note, please remove the & before JFactory

There was a pull request submitted on Github a year ago that allowed Joomla to catch the errors being throw by PHPMailer:


I'm not sure at the implementation but according to the documentation, the send() function will return a JError object if any errors occurred:


  • Thanks for the info. Seems like everything I could find was for previous versions of Joomla. I switched to send from sendMail (and removed the "&"), and it seems to work now. Jun 14, 2017 at 5:09

None of the proposed solutions work. The jMailer return value is a headache because you can't catch exceptions or even know the type of the send() return.

If success returns a boolean true; if not it returns a Jexception object, the two outcomes loosely evaluate as boolean true values!

The simplest way I found is:

$result = $mail->Send();
if ($result === true)  return true;
else  return false;
  • The second link in the accepted answer (to the Joomla docs) shows how to perform a strict check on the result with $send = $mailer->Send(); if ( $send !== true ) { This is just reversing the design of the condition block that you have posted, but effectively the same logic is already provided by the Joomla -- very clearly too. You must have misunderstood the implementation when you tried. Feb 22, 2019 at 21:29

You can get the error using a conditional statement, like so:

if (!$send)
    $error = $send->__toString();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.