So I have this application that I built that uses PHPMailer to send mail. The code works perfectly from my local machine, and it was working perfectly on the server up until yesterday. However now when I run the code on my server I get:
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have literally tried everything. I cannot figure out why this is not working. From the server as the user the site is installed to, I can telnet localhost 465
and I can telnet localhost 587
so the server is up, and its not blocking connections to itself.
The only thing I can think of is, this being a Cpanel server some sort of update must have happened with apache/PHP which caused something to not work right with this. I know the problem is not with the mail server and its not with the code (since it works when I run this exact code from my local machine) which only leaves out the PHP/Apache config on the server...
Does anyone have any insight on what this might be?
PS- I have to use SSL, its the only thing my server supports that I'm aware of,at least I've never had any luck using TLS or unencrypted.
Here is my code:
require("vendor/autoload.php");
$mail = new \PHPMailer;
// set up mail settings
$mail->isSMTP();
$mail->Host = 'my.host.com';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Debugoutput = function($str, $level) {
$GLOBALS['debug'][] = $Host . " - " . $str . " - " . $level;
};
$mail->SMTPDebug = 2;
$mail->CharSet = "UTF-8";
$mail->setFrom(.....);
$mail->addAddress(.....);
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><body>This is the HTML message body <b>in bold!</b></body></html>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
EDIT:
I changed debug level to 3 (for connection debugging, derp) and I get this:
[0]=> string(88) " - Connection: opening to ssl://host.host.com:465, timeout=300, options=array ( ) - 3"
[1]=> string(291) " - Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [/path/to/vendor/phpmailer/phpmailer/class.smtp.php line 294] - 3"
[2]=> string(175) " - Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [/path/to/vendor/phpmailer/phpmailer/class.smtp.php line 294] - 3"
[3]=> string(215) " - Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://my.host.com:465 (Unknown error) [/path/to/vendor/phpmailer/phpmailer/class.smtp.php line 294] - 3"
[4]=> string(52) " - SMTP ERROR: Failed to connect to server: (0) - 1"
[5]=> string(89) " - SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting - 3" }
So I was right, its SSL related... So anyone know how to fix this?