New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'SMTP connect() failed' error on localhost #368

Closed
ozgrozer opened this Issue Feb 24, 2015 · 25 comments

Comments

Projects
None yet
7 participants
@ozgrozer

ozgrozer commented Feb 24, 2015

My settings are true and I can send mail from server but I updated my localhost PHP version to 5.6.3 and now I can't send mail.

I get an error like this

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Applications/XAMPP/xamppfiles/htdocs/phpMailer/class.smtp.php on line 338

What can I do for send emails on localhost?

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Feb 24, 2015

Member

This is covered in the troubleshooting docs. PHP 5.6 verifies SSL certificates by default, and if your cert doesn't match, it will fail with this error. The correct solution is to fix your SSL config - it's not PHP's fault!

If you're sending on localhost you can use isMail() and it won't go through an encryption layer at all.

Member

Synchro commented Feb 24, 2015

This is covered in the troubleshooting docs. PHP 5.6 verifies SSL certificates by default, and if your cert doesn't match, it will fail with this error. The correct solution is to fix your SSL config - it's not PHP's fault!

If you're sending on localhost you can use isMail() and it won't go through an encryption layer at all.

@Synchro Synchro closed this Feb 24, 2015

@ozgrozer

This comment has been minimized.

Show comment
Hide comment
@ozgrozer

ozgrozer Feb 24, 2015

I changed the file class.smtp.php in line 242

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);
    }

and now it works perfect.

ozgrozer commented Feb 24, 2015

I changed the file class.smtp.php in line 242

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);
    }

and now it works perfect.

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Feb 24, 2015

Member

"Perfect" in the sense that you can't detect servers presenting fake credentials, the whole reason this change was made in PHP 5.6. As I said, the correct solution is to fix your SSL, not live with the breakage.
Note that the connect function provides an options parameter in which you can do this without changing the code.

Member

Synchro commented Feb 24, 2015

"Perfect" in the sense that you can't detect servers presenting fake credentials, the whole reason this change was made in PHP 5.6. As I said, the correct solution is to fix your SSL, not live with the breakage.
Note that the connect function provides an options parameter in which you can do this without changing the code.

@ozgrozer

This comment has been minimized.

Show comment
Hide comment
@ozgrozer

ozgrozer Feb 24, 2015

I couldn't fix my SSL and so I found that method.

Now I send options through the smtpConnect function.

$mail->smtpConnect(
    array(
        "ssl" => array(
            "verify_peer" => false,
            "verify_peer_name" => false,
            "allow_self_signed" => true
        )
    )
);

Thanks.

ozgrozer commented Feb 24, 2015

I couldn't fix my SSL and so I found that method.

Now I send options through the smtpConnect function.

$mail->smtpConnect(
    array(
        "ssl" => array(
            "verify_peer" => false,
            "verify_peer_name" => false,
            "allow_self_signed" => true
        )
    )
);

Thanks.

@ivkremer

This comment has been minimized.

Show comment
Hide comment
@ivkremer

ivkremer Apr 22, 2015

@ozgrozer thank you very much, I didn't connect the PHP version upgrade with this error and was wondering why there is such an error when I'm trying to send an email.
My first thoughts were that there is something wrong with a gmail account. Thanks for such an easy and quick solution.

ivkremer commented Apr 22, 2015

@ozgrozer thank you very much, I didn't connect the PHP version upgrade with this error and was wondering why there is such an error when I'm trying to send an email.
My first thoughts were that there is something wrong with a gmail account. Thanks for such an easy and quick solution.

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Jun 8, 2015

Member

This is fixable without touching library code; just do this:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

While that's neat and tidy, it doesn't change the fact that your SSL config is broken 😉

Member

Synchro commented Jun 8, 2015

This is fixable without touching library code; just do this:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

While that's neat and tidy, it doesn't change the fact that your SSL config is broken 😉

@Damiano8

This comment has been minimized.

Show comment
Hide comment
@Damiano8

Damiano8 Jun 29, 2015

where do you write code this $mail ->> SMTP Options = array..?

Damiano8 commented Jun 29, 2015

where do you write code this $mail ->> SMTP Options = array..?

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Jun 29, 2015

Member

In your own code, in the same place you set all the other PHPMailer options.

Member

Synchro commented Jun 29, 2015

In your own code, in the same place you set all the other PHPMailer options.

@Damiano8

This comment has been minimized.

Show comment
Hide comment
@Damiano8

Damiano8 Jun 29, 2015

in class.smtp.php ? or class phpmailer.php?

Damiano8 commented Jun 29, 2015

in class.smtp.php ? or class phpmailer.php?

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Jun 29, 2015

Member

Neither - in your own code.

Member

Synchro commented Jun 29, 2015

Neither - in your own code.

@ivkremer

This comment has been minimized.

Show comment
Hide comment
@ivkremer

ivkremer Jun 29, 2015

@Damiano8 just before you make your $mail->send(), like this:

$mail = new PHPMailer();
$mail->isSMTP(); // $mail->Body = $body; etc
$mail->smtpConnect([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    ]
]);
$mail->send();
$mail->smtpClose();

ivkremer commented Jun 29, 2015

@Damiano8 just before you make your $mail->send(), like this:

$mail = new PHPMailer();
$mail->isSMTP(); // $mail->Body = $body; etc
$mail->smtpConnect([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    ]
]);
$mail->send();
$mail->smtpClose();
@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Jun 29, 2015

Member

No, don't do that - you do not need to call smtpConnect() because PHPMailer does it for you whan you call send(), so doing that results in it trying to connect twice, which will probably fail. This is why the SMTPOptions property exists. Similarly, you don't need to call smtpClose() either as it's done for you.

Member

Synchro commented Jun 29, 2015

No, don't do that - you do not need to call smtpConnect() because PHPMailer does it for you whan you call send(), so doing that results in it trying to connect twice, which will probably fail. This is why the SMTPOptions property exists. Similarly, you don't need to call smtpClose() either as it's done for you.

@Damiano8

This comment has been minimized.

Show comment
Hide comment
@Damiano8

Damiano8 Jun 29, 2015

look guys, i have this warning when i try to send email:

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in D:\xampp15\htdocs\stran\class.smtp.php on line 345
There are some issue.

Damiano8 commented Jun 29, 2015

look guys, i have this warning when i try to send email:

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in D:\xampp15\htdocs\stran\class.smtp.php on line 345
There are some issue.

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Jun 29, 2015

Member

Yes, it's exactly the error this closed ticket is about, and you can solve it as described in the docs already linked to. Please read before posting.

Member

Synchro commented Jun 29, 2015

Yes, it's exactly the error this closed ticket is about, and you can solve it as described in the docs already linked to. Please read before posting.

@Damiano8

This comment has been minimized.

Show comment
Hide comment
@Damiano8

Damiano8 Jun 29, 2015

well now i have included this part of code in my code and it returns the same error as before and another error:
Warning: Creating default object from empty value in D:\xampp15\htdocs\stran\kontakt.php on line 101

Damiano8 commented Jun 29, 2015

well now i have included this part of code in my code and it returns the same error as before and another error:
Warning: Creating default object from empty value in D:\xampp15\htdocs\stran\kontakt.php on line 101

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Jun 29, 2015

Member

That sounds like you have called you PHPMailer instance something other than $mail. Use whatever you have called it instead.

Member

Synchro commented Jun 29, 2015

That sounds like you have called you PHPMailer instance something other than $mail. Use whatever you have called it instead.

@Damiano8

This comment has been minimized.

Show comment
Hide comment
@Damiano8

Damiano8 Jun 29, 2015

could i send you the code so you can take a quick look? because i don't have any ideas what to do anymore..

Damiano8 commented Jun 29, 2015

could i send you the code so you can take a quick look? because i don't have any ideas what to do anymore..

@ivkremer

This comment has been minimized.

Show comment
Hide comment
@ivkremer

ivkremer Jun 29, 2015

@Synchro thank you very much for information about using isSMTP() and smtpClose. I've just copied a snippet like this somewhere without analysing it.

ivkremer commented Jun 29, 2015

@Synchro thank you very much for information about using isSMTP() and smtpClose. I've just copied a snippet like this somewhere without analysing it.

@Damiano8

This comment has been minimized.

Show comment
Hide comment
@Damiano8

Damiano8 Jun 29, 2015

just wanted to let you know that i somehow fixed it. i installed a older version of xampp and it worked.. i was running xampp version 5.6.3 and then i switched to 1.8.1. i mean..this versions..

Damiano8 commented Jun 29, 2015

just wanted to let you know that i somehow fixed it. i installed a older version of xampp and it worked.. i was running xampp version 5.6.3 and then i switched to 1.8.1. i mean..this versions..

@jimobama

This comment has been minimized.

Show comment
Hide comment
@jimobama

jimobama Jul 16, 2015

I really want this problem solved , have done everything said in this thread except configuration of my SSL (Who do you done that) , even update my Linux certificate. everything works on console. Same codes work on windows but when I used it in Linux this error codes up.

jimobama commented Jul 16, 2015

I really want this problem solved , have done everything said in this thread except configuration of my SSL (Who do you done that) , even update my Linux certificate. everything works on console. Same codes work on windows but when I used it in Linux this error codes up.

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Jul 16, 2015

Member

@jimobama This error is because of a config error on your server. Follow the troubleshooting guide and it will tell you what is wrong. This is not a bug in PHPMailer, and we can't fix your server for you.

Member

Synchro commented Jul 16, 2015

@jimobama This error is because of a config error on your server. Follow the troubleshooting guide and it will tell you what is wrong. This is not a bug in PHPMailer, and we can't fix your server for you.

@jimobama

This comment has been minimized.

Show comment
Hide comment
@jimobama

jimobama Jul 16, 2015

Thanks for the reply , the problem lies with my SMTP server Host information and now working fine.

jimobama commented Jul 16, 2015

Thanks for the reply , the problem lies with my SMTP server Host information and now working fine.

@brruoff

This comment has been minimized.

Show comment
Hide comment
@brruoff

brruoff Sep 9, 2015

Works perfect @ozgrozer
thanks

brruoff commented Sep 9, 2015

Works perfect @ozgrozer
thanks

@DavorSaric

This comment has been minimized.

Show comment
Hide comment
@DavorSaric

DavorSaric Mar 1, 2016

Ok, how about a hosting server with 150 websites? We have upgraded from php 5.5 to php5.6 and every web that uses PHPMailer now is broken because contact forms are not working. Is there any fix for this or should we downgrade and freeze php version to 5.5?

DavorSaric commented Mar 1, 2016

Ok, how about a hosting server with 150 websites? We have upgraded from php 5.5 to php5.6 and every web that uses PHPMailer now is broken because contact forms are not working. Is there any fix for this or should we downgrade and freeze php version to 5.5?

@Synchro

This comment has been minimized.

Show comment
Hide comment
@Synchro

Synchro Mar 1, 2016

Member

As already mentioned several times in this thread, read the docs. You can work around this for your entire server by setting PHP to not validate certificates in your php.ini, however, you should be aware that this is the wrong way to fix the problem - it's the mail servers with bad configuration that are at fault, not your web server or PHPMailer.

Member

Synchro commented Mar 1, 2016

As already mentioned several times in this thread, read the docs. You can work around this for your entire server by setting PHP to not validate certificates in your php.ini, however, you should be aware that this is the wrong way to fix the problem - it's the mail servers with bad configuration that are at fault, not your web server or PHPMailer.

@PHPMailer PHPMailer locked and limited conversation to collaborators Mar 1, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.