Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
8.9k views
in Q2A Core by

I try to setup SMTP email through a GMAIL account I have.  It does not work.  Spent a couple of hours testing and changing the settings.  Here are some key settings:

 

Sender address for messages from site:  ask.greek [at] gmail [dot] com

(of course I put it in the correct form)

SMTP server address:
SMTP server port:  
SMTP secure connection:    TLS
YES
SMTP username:
ask.greek [at] gmail [dot] com
SMTP password:  (the gmail password

 

I looked at the error_log and found the following warnings:

[11-Nov-2014 04:35:19 America/Los_Angeles] PHP Warning:  fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number in /home/......./qa-include/qa-class.smtp.php on line 122
[11-Nov-2014 04:35:19 America/Los_Angeles] PHP Warning:  fsockopen(): Failed to enable crypto in /home/...../qa-include/qa-class.smtp.php on line 122
[11-Nov-2014 04:35:19 America/Los_Angeles] PHP Warning:  fsockopen(): unable to connect to tls://smtp.gmail.com:587 (Unknown error) in /home/.........../qa-include/qa-class.smtp.php on line 122

Q2A version: 1.6.3

1 Answer

0 votes
by
edited by

Try using port 465.

If it doesn't fix the issue make sure you read the following: https://support.google.com/mail/answer/78775?hl=en&ref_topic=3397962

Edit: Maybe you don't have SSL enabled in your server. There is a quick test. Create a file zzz.php next to your qa-config.php file and append this content to former:

<?php 
$fp = fsockopen("www.google.com", 80, &$errno, &$errstr, 10); // works fine
if(!$fp)
    echo "www.google.com - $errstr ($errno)<br>\n";
else
    echo "www.google.com - ok<br>\n";
 
$fp = fsockopen("smtp.gmail.com", 465, &$errno, &$errstr, 10); // Does not work
if(!$fp)
    echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n";
else
    echo "smtp.gmail.com 465 - ok<br>\n";
 
$fp = fsockopen("smtp.gmail.com", 587, &$errno, &$errstr, 10); // Does not work
if(!$fp)
    echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n";
else
    echo "smtp.gmail.com 587 - ok<br>\n";
echo "<br />".phpinfo();
 
Then navigate to http://yoursite.com/zzz.php. The expected output should be:
www.google.com - ok
smtp.gmail.com 465 - ok
smtp.gmail.com 587 - ok
 

And a bunch of information about PHP. Use your browser's search and paste ALL relevant SSL information (including the section header). EG, for openssl I have:

OpenSSL support enabled
OpenSSL Library Version OpenSSL 0.9.8o 01 Jun 2010
OpenSSL Header Version OpenSSL 0.9.8o 01 Jun 2010
 
Finally, delete the zzz.php file.
 
Edit2:
If you can't access zzz.php file you can go to your qa-theme.php file and look for function doctype(). Backup (copy/paste) the content of that function. Replace it with the one in this gist: https://gist.github.com/pupi1985/67aff930780d8848d0b9 . Make sure to replace 'admin' with YOUR username. This will show the output when accessing any page but only to you. In order to be able to navigate your site again just get the backed up function text and replace it again.
 
Bear in mind when performing SMTP tests with gmail you should login frequently to the web as sometimes they block the connections and you need to enable them from there.
by
I lessened the security as you suggested.  I use port 587.  It still does not work.  The only improvement is that the error log does not have any related errors.
by
I made one more test.  Now that my IP is not spam-blocked any more.  SMTP from 587 still does not work.  

Why can't we examine the errors from the error log?

[12-Nov-2014 15:26:28 America/Los_Angeles] PHP Warning:  fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number in /home/...../qa-include/qa-class.smtp.php on line 122
[12-Nov-2014 15:26:28 America/Los_Angeles] PHP Warning:  fsockopen(): Failed to enable crypto in /home/....../qa-include/qa-class.smtp.php on line 122
[12-Nov-2014 15:26:28 America/Los_Angeles] PHP Warning:  fsockopen(): unable to connect to tls://smtp.gmail.com:587 (Unknown error) in /home/....../ask-greek/qa-include/qa-class.smtp.php on line 122
by
If the same code works for other people then it must be some kind of server configuration you should change. I would try updating to a newer SSL version but that is something the hosting provider should do. You can give this a last try by updating those 2 mails files from v1.6.3 to the ones in beta-1. You can find them here: https://github.com/q2a/question2answer/tree/dev/qa-include/vendor/PHPMailer . Just replace them. If that doesn't fix the issue you can get the originals back
by
Isn't there anyone that can understand the error and give advice for the cause?

Maybe if I ask the host?  I just hate to ask them and then they answer: "This is custom code and we do not support it".
...