使用Gmail从CakePHP应用程序发送电子邮件

时间:2012-08-17 00:20:37

标签: php email cakephp gmail

我正在努力让我正在开发的网站发送密码提醒电子邮件。我曾想过使用我的Gmail帐户进行测试。从Cake cookbook,我有这个代码:

$this->Email->from = 'support@site.com';
$this->Email->smtpOptions = array(
    'port'=>'465',
    'timeout'=>'30',
    'host' => 'ssl://smtp.gmail.com',
    'username'=>'notmyrealemail@gmail.com',
    'password'=>'notmyrealpassword');
$this->Email->delivery = 'smtp';
$this->Email->from = 'support@imgstore.in';
$this->Email->to = $this->request->data['User']['email'];
$this->Email->subject = 'Your account reset request';
$this->Email->send('testing');
$this->Email->send();
debug($this->Email->smtpError);

但是,当执行此代码时,我发现了这个错误:

Error: Call to a member function messageID() on a non-object    
File: C:\xampp\htdocs\site\lib\Cake\Controller\Component\EmailComponent.php 
Line: 312

Notice: If you want to customize this error message, create app\View\Errors\fatal_error.ctp

我在这里做错了什么?目前我只想测试我的应用程序是否可以正常发送电子邮件。但是,Gmail是一种在生产中向我的用户发送电子邮件的好方法吗?

感谢。

1 个答案:

答案 0 :(得分:0)

它似乎是你没有将组件类包含到控制器中。将EmailComponent包含在控制器文件中。

public $components = array('Email');
相关问题