Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
11.4k 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 did everything, still does not work.
by
Ok, I've added some more ideas
by
I uploaded it with ftp.  But when I go to http://mysite.com/zzz.php I get a BLANK page.  Even when I try to see the page source of the page, I still get a blank page.  Probably my host has disabled some functions in php.  I will ask him.  What do you think?
by
While I wait for the host to reply.  Have you seen the error messages I posted?  I think the first one is the key:

OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number in /home/......./qa-include/qa-class.smtp.php on line 122
by
Why you don't see the page it could be for many reasons: .htaccess, file permissions, paths issues, etc. Maybe the logs can help with that. Anyway, make sure you wait long enough until the page stops loading... it might take a while. Regarding the mail issue itself, that's why I think you don't have SSL enabled (or maybe an old library?), that's why the phpinfo() would be helpful.

As a side note, have you made any kind of core change? I see line 122 (https://github.com/q2a/question2answer/blob/v1.6.3/qa-include/qa-class.phpmailer.php#L122) and it has NO fsockopen function in there. That smells odd. I would download the file from the link and upload it again (click in RAW then save the page)
by
YEs, this is strange.  Seems like my file and the file you gave me are COMPLETELY DIFFERENT.

This is the start of my file:

<?php
/*~ class.phpmailer.php
.---------------------------------------------------------------------------.
|  Software: PHPMailer - PHP email class                                    |
|   Version: 2.0.4                                                          |
|   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  |
|      Info: http://phpmailer.sourceforge.net                               |
|   Support: http://sourceforge.net/projects/phpmailer/                     |
| ------------------------------------------------------------------------- |
|    Author: Andy Prevost (project admininistrator)                         |
|    Author: Brent R. Matzelle (original founder)                           |
| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved.               |
| Copyright (c) 2001-2003, Brent R. Matzelle                                |
| ------------------------------------------------------------------------- |
|   License: Distributed under the Lesser General Public License (LGPL)     |
|            http://www.gnu.org/copyleft/lesser.html                        |
| This program is distributed in the hope that it will be useful - WITHOUT  |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
| FITNESS FOR A PARTICULAR PURPOSE.                                         |
| ------------------------------------------------------------------------- |
| We offer a number of paid services (www.codeworxtech.com):                |
| - Web Hosting on highly optimized fast and secure servers                 |
| - Technology Consulting                                                   |
| - Oursourcing (highly qualified programmers and graphic designers)        |
'---------------------------------------------------------------------------'

/**
 * PHPMailer - PHP email transport class
 * @package PHPMailer
 * @author Andy Prevost
 * @copyright 2004 - 2009 Andy Prevost
 */
by
Just to make sure, I just made a fresh download of the 1.6.3 version from here:  http://www.question2answer.org/versions.php

Then I downloaded with FTP the file in question from my site.  Please note the file that gives the first error is:  .../qa-include/qa-class.smtp.php on line 122
It is NOT /qa-class.phpmailer.php.

This is what I see in both files, at around line 122:

    #connect to the smtp server
    $this->smtp_conn = fsockopen($host,    # the host of the server
                                 $port,    # the port to use
                                 $errno,   # error number if any
                                 $errstr,  # error message if any
                                 $tval);   # give up after ? secs
by
Oh, good point. I've added a second edit. This will give you the information you need. It is dirty but will get the job done
by
>>>
This will show the output when accessing any page but only to you.
<<<
What do you mean?  We are not talking about the zzz.php any more, right?  You want me to browse my Q2A site, right?  

And I will see some kind of diagnostics?  I don't understand what we are looking for.  

Right now the host is investigating the zzz.php issue, so I have to wait.
by
The host gave some insight:  He reverted php from 5.5 to 5.3 and zzz.php worked.  Here is the output:

www.google.com - ok
smtp.gmail.com 465 - Connection timed out (110)
smtp.gmail.com 587 - ok

'--with-openssl=/usr'
 '--with-imap-ssl'


Registered Stream Socket Transports :  tcp, udp, unix, udg, ssl, sslv3, sslv2, tls

curl ssl :  yes
SSL Version     OpenSSL/1.0.1e
imap SSL Support     enabled


But I will put php 5.5 back.  

Any ideas?
by
Same thing with php 5.5:

www.google.com - ok
smtp.gmail.com 465 - Connection timed out (110)
smtp.gmail.com 587 - ok
by
Clearly port 587 is working fine for you. I tried locally on that port using TLS and... it didn't work for me either. However, as I mentioned before, I received an email from google stating an insecure application was trying to access my account and it redirected me to this link https://www.google.com/settings/security/lesssecureapps . I've chenged it to allow insecure access. Tried again for 15 minutes and didn't work. Tried it again and worked :) I guess it took 15 minutes to google to refresh that value or something. If that doesn't help, I'm definitely out of ideas and all I can say is "works for me" :(
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".
...