user2610146 user2610146 - 1 month ago 30
PHP Question

Cakephp 3 Unknown Email error

I wanted to ask about sending emails in cakephp3.

I am using cakephp3 docs, and configured everything as example shows.

But, when i try to send mail, this error appear:

Could not send email: unknown

//app.php
'EmailTransport' => [

'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.gmail.om',
'port' => 465,
'timeout' => 30,
'username' => 'mymail@gmail.com',
'password' => 'password',
'client' => null,
'tls' => null,
],
],


ContactController:

public function contact() {

if (isset($this->request->data) AND ($this->request->is('post'))) {
$email = new Email('default');
if ($email->from(['mymail@gmail.com' => 'My Site'])->to('othermail@gmail.com')->subject('Hello')->send('Message')) {
//pr( 'ok');
}
}
}


My question is, is this generic error message, which may have many reasons, in my opinion, it has no value in context od debug.
Thanks for reply.

ndm ndm
Answer

You want to use an SMTP server, but you've configured to use the Mail transport!

The className option should be set to Smtp. The host should probably also be different (ssl:// prefixed), or you should enable TLS, please be sure that you read through the questions/answers found with the search linked below.

See also