Sending HTML message through PEAR while using SMTP authentication returns an error

前端 未结 4 1824
面向向阳花
面向向阳花 2021-01-13 03:38

I\'m trying to send an HTML message while using SMTP authentication to Gmail in PHP. Here is the script that I am using:

require_once \"Mail.php\";
require_o         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 03:57

    I had this issue and via debugging managed to get all kinds of different errors (below). Strangest thing is that it completely stopped working on about 11/2/2017. I didn't do any updates. Previously it would randomly work so I put in a retry and it always succeeded < 5 tries, until the 2nd. Strange.

    Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Invalid response code received from server (code: -1, response: )]
    fsockopen(): Failed to enable crypto
    fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
    SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
    

    (and so on)

    Another used posted this troubleshooting step that helped me get more errors so I could Google more what could be the cause:

    $result = fsockopen('ssl://smtp.gmail.com', 465, $error_no,
    $error_message, 5);     
    if($result === false) {         
        echo "error no:
    $error_no error message: $error_message";       echo print_r($result,true);     
    }else{      
        echo 'success\n\n';
    }
    

    My fix was to add a CA bundle file, since apparantly PHP couldn't verify the cert of Google:

    • Download CA bundle https://curl.haxx.se/docs/caextract.html & extract to C:\Program Files\PHP\ssl\cacert.pem
    • Specify location in php.ini: openssl.cafile = C:\Program Files\PHP\ssl\cacert.pem

提交回复
热议问题