1

I'm running Windows 10 Pro with IIS hosting PHP 5.6.11. In the past, an older version of PHPMail worked perfectly for sending emails via gmail in this type of windows/IIS/PHP setup. At some point in the past it quit working. So now I'm using the very latest PHPMail library as of January 6, 2018. Here is my simple example taken mostly from this gmail example.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

$mail = new PHPMailer;
$mail->isSMTP(); 
$mail->SMTPDebug = 2;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // TLS only
$mail->SMTPSecure = "tls"; // ssl is depracated
$mail->SMTPAuth = true;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->setFrom($emailFrom, $emailFromName);
$mail->addAddress($emailTo, $emailToName);
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body"); 
$mail->AltBody = 'HTML messaging not supported';

if(!$mail->send()){
    echo "Mailer Error: " . $mail->ErrorInfo;
}else{
    echo "Message sent!";
}

Here is the culprit:

Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [.....\PHPMailer\src\SMTP.php line 405]

How can I solve this?

UPDATE: I found the true source of the problem and updated the error message in this post, but I don't know how to solve it.

6
  • Error code 0 means it cannot connect to host. Check internet connection and check smpt request module like Curl enabled? Commented Jan 5, 2018 at 5:29
  • Have you configured SMTP server on windows 10? If not please follow this article: support.office.com/en-us/article/…
    – maddy23285
    Commented Jan 5, 2018 at 5:38
  • You've based your code on a very old example, so make sure you're using the latest PHPMailer and base your code on the gmail example provided with it. Then read the troubleshooting guide.
    – Synchro
    Commented Jan 5, 2018 at 9:43
  • maddy23285 - I shouldn't have to configure smtp locally because I don't want to use my local smtp - I want to use gmail's smtp server. Commented Jan 5, 2018 at 13:26
  • Synchro, I downloaded the latest PHPMailer, but I see no gmail example in there. Where is it? Commented Jan 5, 2018 at 13:28

4 Answers 4

1

There are many case you have to check like

  • open SSL in enable using you php ini
  • you have to check your firewall that you are successfully able to access gmail server.
  • etc you can find more solution and cases here
4
  • openssl doesn't exist as a setting in my IIS PHP. Any ideas? I'll google on this though. I had already been to the post you provided and I had already tried most of those. Curious about openssl though. Commented Jan 5, 2018 at 13:12
  • look into the following link, hope it will help you out http://www.herongyang.com/PKI/HTTPS-PHP-Configure-PHP-OpenSSL-on-Windows.html Commented Jan 5, 2018 at 13:16
  • I enabled openssl in my php.ini and restarted IIS. No joy. My firewall is turned off. I visited that page you posted, none of those suggestions worked, I believe I tried all of them. I tried TLS and port 587, same error + a bunch of unprintable chars are emitted. Commented Jan 5, 2018 at 13:24
  • can you look into it as well for your gmail account settings. Commented Jan 5, 2018 at 13:29
0

Change below value in your code.

$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = 2; //Get Error Details

Hope that's work.

0
0

I have tried everything that have been written on Stackoverflow but no luck. At last I omitted the line:

$mail->isSMTP();

Of course it is not a solution but in my case I had to solve the problem and it just did it. Now I'm using php's original mail() function. By the way I tried to use Gmail and Hotmail SMTP services. I don't want anyone to spend so much time on this like me.

0

Everything was solved when I installed a correct certificate in IIS.

Not the answer you're looking for? Browse other questions tagged or ask your own question.