Cant send an email on cakephp3


#1

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)

I also set up wamp for email and I still get the same 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,

    ],
],

#2

Make sure you have TLS enabled, it will prepend ssl:// to the host automatically:

'gmail3' => [
    'className' => 'Smtp',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'timeout' => 30,
    'username' => 'jjxxx@gmail.com',
    'password' => 'xxx',
    'client' => null,
    'tls' => true
]

#3

This didnt work as I got

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)


#4

I have exactly the same problem.

On my developement-machine (vagrant with ubuntu/trusty32, nginx, php7, CakePHP 3.3.0) I am having no problems to connect the smtp-server an send mails.

On the production-server (a cloud-based service, php7) I get the described error.
I found this post describing a similar behaviour. But my SSL-skills are not very good. Maybe this helps to investigate the cause of the error.


#5

Hi, The post seems be the the solution but I dont know how to implement a solution from that website in my windows wamp64 so I am kind of stuck


#7

Also check this:

  • OpenSSL should be configured on your production server
  • If you want to use Gmail as email relay, you will need to have access for less secure apps enabled in your Google account for this to work: support article.

Source: http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports


#8

I have openssl on my wamp loaded.

I cant get anywhere with emails in cakephp3 and I need them. Any help please


#9

It works if I add in these lines as I have php >5.6 . This is not in the docs of cakephp3

‘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
]
]


#10

This works but the code isnt in the docs, Is there a problem with the docs on this point?


#11

It Worked for me, tnx.