minadreapta Posted March 16, 2017 Share Posted March 16, 2017 (edited) Hello, i am trying to use Secure SMTP for sending emails in WHMCS. I set SMTP port to 465 and check the SSL checkbox. I already use SSL for sending emails in Outlook and Thunderbird for several years without problems using 465 port and SSL. When i try to send an email from WHMCS with the above settings i get an error: An Error OccurredSMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting If i enable SMTP_debug in configuration.php i get this error: 2017-03-16 06:38:33 Connection: opening to ssl://mailserver.domain.com:465, timeout=300, options=array ( ) 2017-03-16 06:38:33 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): Peer certificate CN=`hostname.domain.com' did not match expected CN=`mailserver.domain.com' 2017-03-16 06:38:33 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): Failed to enable crypto 2017-03-16 06:38:33 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://mailserver.domain.com:465 (Unknown error) 2017-03-16 06:38:33 SMTP ERROR: Failed to connect to server: (0) 2017-03-16 06:38:33 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Email Sending Failed - SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting i tried editing the vendor/phpmailer/phpmailer/class.phpmailer.php and set the public $SMTPAutoTLS = false; but still no success. i can see it is complaining that mailserver doesn't match the hostname. the mailserver is not the same with the server's hostname (should it be?) the mailserver is on separate IP address (different class) than the hostname IP. is htere any setting i can make in order to have the SSL SMTP working in WHMCS 7? Thanks. LE: forgot to mention: the error started after i upgraded PHP version to 5.6 Edited March 16, 2017 by minadreapta 0 Quote Link to comment Share on other sites More sharing options...
WHMCS ChrisD Posted March 16, 2017 Share Posted March 16, 2017 Hey Minadrepta, Thanks for your post. PHP 5.6 introduced new SSL requirements where it forces an SSL connection for SMTP. The issue here is that you don't have a valid SSL certificate for the SMTP Mail server entered into WHMCS. A temporary work around for you to use while you get the SSL certificate to report back valid is to do the following: Open the file WHMCSROOT/vendor/phpmailer/phpmailer/class.smtp.php and Find around line 247 the function public function connect($host, $port = null, $timeout = 30, $options = array()) { static $streamok; Add the following code so the function reads public function connect($host, $port = null, $timeout = 30, $options = array()) { if( count( $options ) == 0 ) { $options["ssl"] = array( "verify_peer" => false, "verify_peer_name" => false, "allow_self_signed" => true ); } static $streamok; Save the file NOTE: This is only a temporary work around as any full release upgrades of WHMCS will overwrite the change. Details of this workaround can be found at https://github.com/PHPMailer/PHPMailer/issues/368 Another workaround which can be applied are published at https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#php-56-certificate-verification-failure 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted March 16, 2017 Author Share Posted March 16, 2017 after googling for a whilie i found a dirty workaround. i added some options to the class.phpmailer.php: 'verify_peer' => true, 'verify_peer_name' => false and 'allow_self_signed' => false public $SMTPOptions = array( 'ssl' => array( 'verify_peer' => true, 'verify_peer_name' => false, 'allow_self_signed' => false ) ); now the emails get send using the SSL option mentioned above. any other thoughts on this? thanks. 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted March 16, 2017 Author Share Posted March 16, 2017 Hi ChrisD, the certificate is valid, i already use it on email clients without problems: 0 Quote Link to comment Share on other sites More sharing options...
WHMCS ChrisD Posted March 16, 2017 Share Posted March 16, 2017 I'd recommend chatting with your Server Admin, PHP can be moody so often But the giveaway was "Peer certificate CN=`hostname.domain.com' did not match expected CN=`mailserver.domain.com' " 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted March 16, 2017 Author Share Posted March 16, 2017 after half a day of searching and struggling i found out the error was because the hostname SSL certificate was expired. Not the mailserver certificate, not the whmcs domain, but the hostname, after renewing the hostname certificate the error dissapeared. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.