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

使用Gmail从CakePHP应用程序发送电子邮件,php,email,cakephp,gmail,Php,Email,Cakephp,Gmail,我正在尝试让我正在开发的网站发送密码提醒电子邮件。我想用我的Gmail帐号来测试一下。从蛋糕食谱中,我得到了以下代码: $this->Email->from = 'support@site.com'; $this->Email->smtpOptions = array( 'port'=>'465', 'timeout'=>'30', 'host' => 'ssl://smtp.gmail.com', 'username'=

我正在尝试让我正在开发的网站发送密码提醒电子邮件。我想用我的Gmail帐号来测试一下。从蛋糕食谱中,我得到了以下代码:

$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是否是一种向我的生产用户发送电子邮件的体面方式


谢谢。

看起来您的控制器中没有包含组件类。将
EmailComponent
包含到控制器文件中

public $components = array('Email');

为什么不直接使用本地sendmail?:)最好使用新的CakeEmail类,而不是组件。该错误可能是由于在调用send()之前没有设置主题造成的,尽管您的代码显示您已经设置了主题。这是导致此致命错误的实际代码吗?您还调用了send()两次。我的conroller中包含了电子邮件组件。