Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Unable to connect via TLS #202

Open
phantien94 opened this issue Apr 6, 2018 · 6 comments
Open

Unable to connect via TLS #202

phantien94 opened this issue Apr 6, 2018 · 6 comments

Comments

@phantien94
Copy link

I have a problem when I send mail to client to Reset Password. I using Gmail

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 C:\wamp64\www\zend2112\vendor\zendframework\zend-mail\src\Protocol\Smtp.php on line 216

Here is my function:

function sendMailWithToken($user){
        $token = $user->getToken();
        $http = isset($_SERVER['https']) ? 'https://': "http://";
        $domail = $_SERVER['HTTP_HOST'];
        $link = $http.$domail.'/zend/public/set-password/'.$token;

        $messageBody = "Hello ".$user->getFullname(). ',\n';
        $messageBody.="Click the LINK below to reset your password: \n";
        $messageBody.=$link;
        $messageBody.=".\nThanks and Best Regards!";

        $html = new MimePart($messageBody);
        $html->type = "text/html";

        $body = new MimeMessage();
        $body->setParts(array($html));


        $message = new Message();
        $message->setEncoding("UTF-8");
        $message->addFrom('test@gmail.com', 'Forget Password');
        $message->addTo($user->getEmail());
        $message->setSubject('Forget Password');
        $message->setBody($body);

        // Setup SMTP transport
        $transport = new SmtpTransport();
        $options   = new SmtpOptions([
            'name' => 'smtp.gmail.com',
            'host' => 'smtp.gmail.com',
            'port' => 587,
            'connection_class'=>'login',
            'connection_config'=>[
                'username' =>'test@gmail.com',
                'password' => 'password',
                'ssl'      => 'tls',
                
            ],           
        ]);
        $transport->setOptions($options);
        $transport->send($message);
    }

Thanks for reading. I try to fix 2 days. Please help !!!

@ZoltanDobrovolni
Copy link

I have the same issue.
Did you solve it somehow?

@Xerkus
Copy link
Member

Xerkus commented Jun 25, 2018

Your system CA certificates are most likely stale. If on linux check for ca-certs or ca-certificates package. Try to update it first.

If that does not work you need to point ini option to a fresh cafile location:
https://secure.php.net/manual/en/openssl.configuration.php

Take a look at https://github.com/paragonie/certainty
It is an easy way to get fresh ca certificates bundle file.

I, personally, prefer to use this script from curl library to obtain latest certificates directly from mozilla during php setup:
https://github.com/curl/curl/blob/master/lib/mk-ca-bundle.pl

This component might have a configuration option to provide those explicitly to be set as a stream context, I didn't check.

@ZoltanDobrovolni
Copy link

Thanks for your help!

Unfortunatelly, we could not make it working with updated certificates.
So we avoided the problem with other solution.

@RAIMUNDOS54
Copy link

What was it?

Thanks for your help!

Unfortunatelly, we could not make it working with updated certificates.
So we avoided the problem with other solution.

@galvao
Copy link

galvao commented Nov 22, 2018

Not sure if this helps, but anyway...
I was able to connect to my GMail account after enabling "Less secure applications" on it's settings.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-mail; a new issue has been opened at laminas/laminas-mail#30.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants