CakePHP 2.0: CakeEmail Disappointment

In Cake 1.3, MailComponent did what it should do. The new Cake Email class in 2.0 was disappointing .... No emails sent, no errors .... undefined documentation ...

I tried all possible options, tried it using SMTP, Mail () and Gmail, nothing happens. Hereby is my last attempt:

Controller Debugger:

//on top of page
App::uses('CakeEmail', 'Network/Email');


//in method
$email = new CakeEmail();
$email->template('contact_email')
->emailFormat('text')
->to('my@gmail.com')
->from('other@gmail.com')
->send();

Email.php configuration file:

class EmailConfig {

//It also does not work with a constructor

public $gmail = array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'username' => 'my@gmail.com',
    'password' => '***',
    'transport' => 'Smtp'
);

Someone can send a WORK code for an email class. Many thanks

+5
source share
3 answers

I think you should explicitly load your configuration from Config / email.php, it does not load automatically, not even by default:

$email = new CakeEmail();
$email->config('default');

//or in constructor::
$email = new CakeEmail('default');
+9
source

-, :

$email = new CakeEmail('gmail');
+3

. .

class EmailConfig {

    public $default = array(
        'transport' => 'Mail',
        'from' => 'Admin <no-reply@example.com>',       
        'charset' => 'utf-8',
        'headerCharset' => 'utf-8',
    );

}

$email    = new CakeEmail();

$result   = $email->template('welcome')
              ->emailFormat('text')
              ->to($NewUser['email'])
              ->from('admin@example.com')
              ->send();
var_dump($result);
+1
source

All Articles