If you have issues with SMTP emails, you can get Joomla to record all the detailed messages exchanged with your SMTP server.  Inspecting the low level transaction log often allows you to see what is going on between the two servers and resolve any connectivity issues with your IT or hosting provider.  This custom method is quite simple to set up if you have FTP or SSH access to the Joomla folder in your web server.

This SMTP debug option involves a temporary modification to a file in the JMail class, an extension of the PHPMailer library. Warning: core modifications are not recommended and you should revert the file back to the original version as soon as possible.

First make a backup copy of the file your are going to modify, libraries/joomla/mail/mail.php.  Then edit this file, mail.php, and add the following lines to the beginning of the function useSMTP(), after line 634:

// 20170221 SMTP log
$this->SMTPDebug = 4; // maximum level data output
// $this->Debugoutput = 'error_log'; // use the PHP error log, as configured in php.ini
$this->Debugoutput = function($message, $level) { $file = 'mail_log.txt'; $config = JFactory::getConfig(); $logfile = $config['log_path'] . '/' . $file;
$log = fopen($logfile, 'a'); fwrite ($log, $message); fclose($log);};
// 20170221 end

After you click the button Send Test Mail in the Global Configuration or any other mail function, you can download the file 'mail_log.txt' from the Joomla log folder, usually administrator/logs.  

Remember to restore the original version of the file mail.php before the log file grows too much.

And here is the way you can log the mail debug entries by using the standard debug option.  Configure the plugin 'System - Debug' with the following key settings:

  • Allowed Groups: Super Users
  • Log Priorities:  All
  • Log Categories: mail
  • Log Almost Everything

Turn on the debug option in Global Configuration and you can find all the details of the SMTP connection requests and responses with error codes from the file administrator/logs/everything.php.




Make sure you have Google 2-Step Verification turned on: https://www.google.com/landing/2step/

As explained in this article: https://support.google.com/accounts/answer/185833?hl=en, create an application specific password, "App Password", 'my-app-password' below, for your SMTP connection: https://security.google.com/settings/security/apppasswords

Now you can use the following mail settings:

Mailer SMTP
SMTP Host smtp.gmail.com
SMTP Port 587
SMTP Authentication Yes
SMTP Username This email address is being protected from spambots. You need JavaScript enabled to view it.
SMTP Password my-app-password

If your site used to send its emails through the Gmail SMTP server and stopped after the latest Joomla update, you can restore the sending by modifying one of Joomla files.  Modifying core files is not recommended but sometimes it has to be done as an emergency measure, until a permanent remedy has been implemented in the applications involved.

Versions of Joomla before 3.6.0 used to work with Gmail by using an app password, created from the 2-Step Verification page of Google Accounts at https://security.google.com/settings/security/apppasswords

After the update to version 3.6.0, the connection to smtp.gmail.com reports a failure in the verification of the server certificate:

[28-Jul-2016 09:54:34 UTC] PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:

error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\www\joomla360\libraries\vendor\phpmailer\phpmailer\class.smtp.php on line 343

As instructed under "PHP 5.6 certificate verification failure" at https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting, you can set the Options parameter to bypass the verification of the server certificate.

The following code can be added as a workaround to the beginning of the function useSmtp() in the file libraries/joomla/mail/mail.php:

   // 20160729 workaround for certificate verification failure - ref. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    $this->SMTPOptions = array(
    'ssl' => array(
      'verify_peer' => false,
      'verify_peer_name' => false,
      'allow_self_signed' => true
    // 20160729 end

If you want to troubleshoot the SMTP connection to your outgoing mail server, you can do that by setting the existing debug option in the PHPMailer library, which executes the mail functions in Joomla.  This allows you to log the data, mail commands and the connection status to the PHP error log.

Please note that core modifications are not recommended and the following instructions assume that you revert the file to the original version as soon as possible.

Edit the file libraries/joomla/mail/mail.php and add the following lines to the beginning of the function useSmtp(), after line 467:

      // debug SMTPmailer
      // $this->SMTPDebug    = 3;        // output data, commands and connection status
      $this->SMTPDebug    = 4;           // low level data output, all messages
      $this->Debugoutput   = 'error_log';   // output to error log as configured in php.ini

That is all you need to do in Joomla 3.5.0.   There is a small additional modification you need to do for Joomla 3.4.8, documented in this article: Debugging SMTP Mail in Joomla 3.4.8

Once you run the mail function, for example by using Mass Mail to a small group of test users including yourself, you can see detailed messages in the PHP error log, for example this failed connection:

[19-Mar-2016 10:47:39 Europe/London] Connection: opening to smtp.gmail.com:587, timeout=10, options=array (  )

[19-Mar-2016 10:47:49 Europe/London]SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)

If the SMTP server responds and the connection succeeds, you can see the whole SMTP dialogue in the log file:

[23-Mar-2016 12:47:52 Europe/London] Connection: opening to smtp.gmail.com:587, timeout=300, options=array (  )

[23-Mar-2016 12:47:52 Europe/London] Connection: opened

[23-Mar-2016 12:47:52 Europe/London] SMTP -> get_lines(): $data is ""

[23-Mar-2016 12:47:52 Europe/London] SMTP -> get_lines(): $str is  "220 smtp.gmail.com ESMTP t7z282442970wjf.39 - gsmtp

Make sure that you go back to the original version of the file mail.php before the log file starts growing unnecessarily.

Page 1 of 3