Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 2.0: CakeEmail frustration

Tags:

cakephp-2.0

In Cake 1.3, the EmailComponent did what it should do. The new Cake Email class in 2.0 turned out to be a frustration....No emails sent, No errors....vague documentation...

I have tried all possible variants, tried it with my SMTP, Mail() and Gmail, nothing happens. Hereby my latest attempt:

Controller snippet:

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


//in method
$email = new CakeEmail();
$email->template('contact_email')
->emailFormat('text')
->to('[email protected]')
->from('[email protected]')
->send();

Email.php Config file:

class EmailConfig {

//It also does not work with a constructor

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

Can someone please post WORKING code for the Email Class. Many thanks

like image 565
ChrisDK Avatar asked Dec 01 '11 13:12

ChrisDK


2 Answers

In my opinion you should use this:

$email = new CakeEmail('gmail');
like image 37
Roman Avatar answered Nov 13 '22 14:11

Roman


I think you have to load your config from Config/email.php explicitly, it is not loaded automatically, not even the default config:

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

//or in constructor::
$email = new CakeEmail('default');
like image 148
ZiziTheFirst Avatar answered Nov 13 '22 16:11

ZiziTheFirst