0

AppController我正在尝试从我的 CakePHP 2.0 应用程序中发送电子邮件。如果我从 发送它可以正常工作PagesController,但我也需要能够发送AppController

我有:

function sendSystemEmail($to = EMAIL_CONTACT, $from = EMAIL_FROM, $subject = null, $body = null, $view = null, $vars = null) {
    App::uses('CakeEmail', 'Network/Email');
    $email = new CakeEmail();
    $email->viewVars(array(
            'body' => $body,
            'vars' => $vars
    ));
    $email->template($view)
            ->emailFormat('html')
            ->from($from)
            ->to($to)
            ->subject($subject)
            ->send();
    return;
}

当我使用它时,我没有收到任何错误,但电子邮件没有到达。我看不出这和我的代码有什么不同PagesController,所以我假设有些东西可能AppController无法访问?我不知道是什么!

4

1 回答 1

0

Sharon,你没有放配置方法..这个参数也可以放在classEmail的构造函数中,这样..

$email = new CakeEmail('pop3'); //can be smtp or the protocole you are using..

或者

$email->config('pop3')

你需要在这里定义连接 ../app/Config/email.php

class EmailConfig {

    public $pop3 = array(
        'transport' => 'Mail',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    );
于 2012-05-18T23:30:55.490 回答