0
votes

I can't get cakephp3 to send emails. In cakephp2 I could do this no problem. I am using the latest WAMP, and cakephp3.3 on Windows 7. I tried to follow the directions but it looks like I am getting something basic wrong. Do I also need to configure Wamp as I checked the php.ini-development file but there is no smtp entry to change

error- stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed stream_socket_client(): Failed to enable crypto stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)

controller

   public function singleTutorEmail(){


       $email = new Email();
       $email->transport('gmail3');

       $to='[email protected]';
       $subject='testing';
       $message='hello, dfsfsdfsdf sdfsdf';

       $email->from(['[email protected]' => 'test'])
                  ->to($to)
                  ->subject( $subject)                   
                  ->send($message);
}

in app.php

   'EmailTransport' => [
        'default' => [
            'className' => 'Mail',
            // The following keys are used in SMTP transports
            'host' => 'localhost',
            'port' => 465,
            'timeout' => 30,
            'username' => 'user',
            'password' => 'secret',
            'client' => null,
            'tls' => null,
            'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
        ],
   'gmail3' => [
              'className' => 'Smtp',
             'host' => 'ssl://smtp.gmail.com',
            'port' => 465,
            'timeout' => 30,
            'username' => '[email protected]',
            'password' => 'xxx',
            'client' => null,
           'context' => [
          'ssl' => [
          'verify_peer' => false,
          'verify_peer_name' => false,
             'allow_self_signed' => true
                 ]
             ]

        ],
    ],

http://book.cakephp.org/3.0/en/core-libraries/email.html
Sending Mail using CakePHP 3.0

1
if you want to use gmail then the className should be Smtp and not Mail. - arilia
Ok but after that I get this new error ---stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol stream_socket_client(): Failed to enable crypto stream_socket_client(): unable to connect to ssl://smtp.gmail.com:25 (Unknown error) - ajt
because 25 is not the standard smtp port. Try 465 - arilia
yes i tried this 465 port and no difference. I will update what I have on the OP - ajt
It works if I add in these lines as I have php >5.6 . This is not in the docs of cakephp3 'context' => [ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ] - ajt

1 Answers

0
votes

I had the same issue when making an HTTPS request using Cake\Network\Http\Client

To resolve the problem, I had to download "cacert.pem" file from https://curl.se/ca/cacert.pem

And then I updated php.ini by adding the following line:

openssl.cafile = <PATH_TO_CACERT_PEM>/cacert.pem

Don't forget to restart the web-server. If the above thing doesn't make it work, try to update the OpenSSL library installed on your system.

I really hope this works for you too.