CakeEmail调试 [英] CakeEmail debug

查看:76
本文介绍了CakeEmail调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的控制器中设置一个测试电子邮件,输出电子邮件,而不实际发送电子邮件。我使用CakePHP 2.1

I'm trying to set up a test email in my controller that outputs the email as it would look, without actually sending the email. I am using CakePHP 2.1

在我的控制器顶部有:

App::uses('CakeEmail', 'Network/Email');

在我的控制器中的方法是:

And in my controller the method is:

$email = new CakeEmail('default');  
$email->from(array('me@example.com' => 'My Site'));  
$email->to('you@example.com');  
$email->subject('About');  
$email->send('My message');

在我的电子邮件配置中,我将$ default设置为调试模式:

In my email config I have set the $default to Debug mode:

public $default = array(
    'transport' => 'Debug',
    'from' => 'you@localhost.com',
    //'charset' => 'utf-8',
    //'headerCharset' => 'utf-8',
);

如何输出电子邮件?

推荐答案

构建具有启用日志功能的CakeEmail:

Construct the CakeEmail with log enabled:

$Email = new CakeEmail(array('log' => true));

以下代码是CakeEmail类send()方法的摘录,解释。

The following code is an excerpt of the CakeEmail classes send() method, it should be pretty self-explaining.

    $contents = $this->transportClass()->send($this);
    if (!empty($this->_config['log'])) {
        $level = LOG_DEBUG;
        if ($this->_config['log'] !== true) {
            $level = $this->_config['log'];
        }
        CakeLog::write($level, PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message']);
    }
    return $contents;

因此,您的电子邮件将会出现在该日志文件中。

So your email will end up in that log file.

如果你不喜欢编写你自己的运输类和日志到数据库,会话或只是debug()在你的运输类的输出,你喜欢!

If you don't like that feel free to write your own transport class and log to database, session or simply debug() the output in your transport class, do as you like!

这篇关于CakeEmail调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆