Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:



  • If your software, using PHPMailer to send out messages via gmail (Google Mail) account, stops working when sending mail (SMTP) and it gives an error like:

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out)

    the possible reason is the firewall that is blocking outgoing communication on port 465.

    to test if you can connect to the google smtp server, use this command (Linux shell):

    openssl s_client -connect smtp.gmail.com:465
    
    ```*if nothing happens for a long time, than you get a "connection timed out" message, it may be the firewall
    
    **SOLUTION:** This solution will work on **cPanel/WHM** powered servers with **CSF** (ConfigServer Security&Firewall) *on other servers use SSH and vi to edit CSF and restart the service after making the changes
    
    *   Log into WHM as root and access "ConfigServer Security&Firewall" settings (on left, at the bottom, under Plugins)
    *   Click "Firewall Configuration" button
    *   Find: # Lists of ports in the following comma separated lists can be added using a colon (e.g. 30000:35000).
    *   Under "# Allow outgoing TCP ports"
        check the "**TCP_OUT =**" list if you see port **465** listed (usually between port 443 and 587). If not:
    *   include port 465 in the list, scroll down and click "Change"
    *   restart CSF firewall
    
    test if you can connect to the google smtp server again:
    

    openssl s_client -connect smtp.gmail.com:465


 

Looks like your connection to H7 was lost, please wait while we try to reconnect.