SMTP connect() failed - With GMail account

Need help with the Administration of your Joomla! 3.x site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
Mikeee404
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Dec 30, 2013 6:54 pm

SMTP connect() failed - With GMail account

Post by Mikeee404 » Wed Jul 27, 2016 7:32 pm

Sorry I know this question has been asked and asked, but I have yet to find an answer that works or more specifically applies to Joomla 3.6.0.

I am trying to troubleshoot the issue myself as much as possible to avoid bothering the forum with this, but that is a part of the problem. I have found multiple posts about inserting two lines of code into the /libraries/joomla/mail/mail.php file, but they all refer to incorrect line numbers (because they refer to older versions of Joomla) and when I try the two lines in various areas based on searches for the same function in the newer version it does not output any log info to the 'error_log' file at all.

Here is the code I have tried in various places in mail.php file:

Code: Select all

$this->SMTPDebug    = 4;
$this->Debugoutput   = 'error_log';
the instructions I have seen also say
add the following lines to the beginning of the function useSmtp(), after line 467
Could someone provide an actual example of what that section of code should look like for Joomla 3.6 like below around line 625 (is this supposed to work?):

Code: Select all

	public function useSmtp($auth = null, $host = null, $user = null, $pass = null, $secure = null, $port = 25)
	{
		$this->SMTPDebug    = 4;
      	        $this->Debugoutput   = 'error_log';
		$this->SMTPAuth = $auth;
		$this->Host = $host;
		$this->Username = $user;
		$this->Password = $pass;
		$this->Port = $port;

		if ($secure == 'ssl' || $secure == 'tls')
		{
			$this->SMTPSecure = $secure;
		}

		if (($this->SMTPAuth !== null && $this->Host !== null && $this->Username !== null && $this->Password !== null)
			|| ($this->SMTPAuth === null && $this->Host !== null))
		{
			$this->isSMTP();

			return true;
		}
		else
		{
			$this->isMail();

			return false;
		}
	}
Here is the config in the admin area, this on a GoDaddy shared hosting plan with PHP 5.6 enabled:
Joomla-SMTP_Config.jpg
Thanks for any assistance you can provide!
You do not have the required permissions to view the files attached to this post.

NickC4555
Joomla! Explorer
Joomla! Explorer
Posts: 457
Joined: Sun Jan 30, 2011 10:09 am
Location: Leicester, UK

Re: SMTP connect() failed - With GMail account

Post by NickC4555 » Wed Jul 27, 2016 9:06 pm

You can get GMail to work with Joomla without modifying any code. Enable 2 step authentication on your Google account. In the Password & sign-in method in the Signing in to Google section of My Account you will now see an additional option, App Passwords. Generate a password for your website and use that in place of the regular one.

Mikeee404
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Dec 30, 2013 6:54 pm

Re: SMTP connect() failed - With GMail account

Post by Mikeee404 » Thu Jul 28, 2016 12:25 am

Just tried that, still no go. Still have no clue why since there is no log info to determine if it is a connection problem, authentication problem, etc...

Appreciate the suggestion though.

NickC4555
Joomla! Explorer
Joomla! Explorer
Posts: 457
Joined: Sun Jan 30, 2011 10:09 am
Location: Leicester, UK

Re: SMTP connect() failed - With GMail account

Post by NickC4555 » Thu Jul 28, 2016 6:06 am

That's odd, I have GMail working using that method on a couple of sites. Perhaps J3.6 breaks it.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 14027
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: SMTP connect() failed - With GMail account

Post by toivo » Thu Jul 28, 2016 7:19 am

The Joomla debug option is supposed to log the SMTP events in 3.6.0 but this does not seem to work.

You can turn on SMTP debugging by modifying line 112 in the file libraries/vendor/phpmailer/class.smtp.php:

Code: Select all

    // public $do_debug = self::DEBUG_OFF;
	public $do_debug = self::DEBUG_LOWLEVEL;
Toivo Talikka, Global Moderator

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 14027
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: SMTP connect() failed - With GMail account

Post by toivo » Thu Jul 28, 2016 10:52 am

As mentioned by NickC4555, Gmail used to work with an app password, created from the 2-Step Verification page of Google Accounts at https://security.google.com/settings/se ... ppasswords.

Now that method fails, complaining about the SSL certificate of the mail server:

Code: Select all

[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/ ... leshooting, you can set the Options parameter to bypass the verification of the server certificate.

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

Code: Select all

		public function useSmtp($auth = null, $host = null, $user = null, $pass = null, $secure = null, $port = 25)
	{
		// SMTP logging
		$this->SMTPDebug	= 4;
		$this->Debugoutput  = 'error_log';
		// 20160728 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
			)
		);	
		// 20160728 end		
		
		$this->SMTPAuth = $auth;
Tested in PHP 5.6.19 and 7.0.4 in Wampserver 3, OpenSSL/1.0.2g
Toivo Talikka, Global Moderator

Mikeee404
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Dec 30, 2013 6:54 pm

Re: SMTP connect() failed - With GMail account

Post by Mikeee404 » Thu Jul 28, 2016 3:58 pm

Thanks Toivo, I will give that a try.

Mikeee404
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Dec 30, 2013 6:54 pm

Re: SMTP connect() failed - With GMail account

Post by Mikeee404 » Thu Jul 28, 2016 4:43 pm

Ok, so I changed the file /libraries/vendor/phpmailer/phpmailer/class.smtp.php {line 112} to:

Code: Select all

    //public $do_debug = self::DEBUG_OFF;
    public $do_debug = self::DEBUG_LOWLEVEL;
and adjusted the code in /libraries/joomla/mail/mail.php {line 627} to:

Code: Select all

	public function useSmtp($auth = null, $host = null, $user = null, $pass = null, $secure = null, $port = 25)
   	{
      // SMTP logging
      		$this->SMTPDebug   = 4;
      		$this->Debugoutput  = 'error_log';
      // 20160728 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
         		)
      		);   
      // 20160728 end        
     		$this->SMTPAuth = $auth;
		$this->Host = $host;
		$this->Username = $user;
		$this->Password = $pass;
		$this->Port = $port;

		if ($secure == 'ssl' || $secure == 'tls')
		{
			$this->SMTPSecure = $secure;
		}

		if (($this->SMTPAuth !== null && $this->Host !== null && $this->Username !== null && $this->Password !== null)
			|| ($this->SMTPAuth === null && $this->Host !== null))
		{
			$this->isSMTP();

			return true;
		}
		else
		{
			$this->isMail();

			return false;
		}
	}
Site will not send email yet and I am getting the same error message in the admin area, plus there is still no log info in the web root "error_log" file. Seriously scratching my head on this one.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 14027
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: SMTP connect() failed - With GMail account

Post by toivo » Thu Jul 28, 2016 7:58 pm

Turn on the Debug option in Global Configuration and see if that gets the logging started.
Toivo Talikka, Global Moderator


Locked

Return to “Administration Joomla! 3.x”