CakePHP 2.0: CakeEmail frustration

烂漫一生 提交于 2019-12-12 07:18:57

问题


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('my@gmail.com')
->from('other@gmail.com')
->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' => 'my@gmail.com',
    'password' => '***',
    'transport' => 'Smtp'
);

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


回答1:


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');



回答2:


In my opinion you should use this:

$email = new CakeEmail('gmail');



回答3:


This is my email config file . I didnt do any change here

class EmailConfig {

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

}

This is how i send the mail

$email    = new CakeEmail();

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


来源:https://stackoverflow.com/questions/8342139/cakephp-2-0-cakeemail-frustration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!