0

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='jjxxx@gmail.com';
       $subject='testing';
       $message='hello, dfsfsdfsdf sdfsdf';

       $email->from(['jjxxx@gmail.com' => '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' => 'jjxxx@gmail.com',
            '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

Community
  • 1
  • 1
ajt
  • 642
  • 2
  • 6
  • 21
  • if you want to use gmail then the className should be `Smtp` and not `Mail`. – arilia Aug 24 '16 at 06:31
  • 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 Aug 24 '16 at 06:44
  • because 25 is not the standard smtp port. Try 465 – arilia Aug 24 '16 at 06:49
  • yes i tried this 465 port and no difference. I will update what I have on the OP – ajt Aug 24 '16 at 06:52
  • did you told gmail you are trying to access to the email from your application? [link](https://support.google.com/accounts/answer/6010255) – arilia Aug 24 '16 at 06:56
  • PS still see 'className' => 'Mail' in your code after the edit. Is it just a typo? – arilia Aug 24 '16 at 06:57
  • yes it is a typo, I have Smtp for classname – ajt Aug 24 '16 at 06:59
  • I used the same email for the cakephp2 version without an issue, what would I do in gmail for the cakephp3 version of sending emails ? – ajt Aug 24 '16 at 07:00
  • are tring in localhost or live server? – Kamlesh Gupta Aug 24 '16 at 07:22
  • If you are using gmail as host , do you have correctly set Grant access to your account for less secure apps? – Martin Hrabal Aug 24 '16 at 07:50
  • I can use the same email with my cakephp2 email setup so what am I looking for the is stopping cakephp3 from working on my localhost? – ajt Aug 24 '16 at 11:51
  • I tried setting up wamp for emails but i still get the same error as above in OP, http://stackoverflow.com/questions/22396721/how-to-send-email-from-localhost-wamp-server-to-send-email-gmail-hotmail-or-so-f – ajt Aug 24 '16 at 12:56
  • I had another try at this email and I cant get it to work still as I have the same error in the OP when it sends an email. The openssl module is loaded in WAMP. Can anyone please help – ajt Sep 22 '16 at 07:46
  • 2
    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 Sep 22 '16 at 09:14

1 Answers1

0

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.

Main Pal
  • 449
  • 5
  • 14