2012-08-17 122 views
0

我试图让我正在开发的网站发送密码提醒电子邮件。我有想用我的Gmail帐户来测试。从蛋糕食谱,我有这样的代码:使用Gmail从CakePHP应用程序发送电子邮件

$this->Email->from = '[email protected]'; 
$this->Email->smtpOptions = array(
    'port'=>'465', 
    'timeout'=>'30', 
    'host' => 'ssl://smtp.gmail.com', 
    'username'=>'[email protected]', 
    'password'=>'notmyrealpassword'); 
$this->Email->delivery = 'smtp'; 
$this->Email->from = '[email protected]'; 
$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); 

然而,当这个代码执行GES我歌厅此错误:

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是否会将电子邮件发送给我的用户?

谢谢。

+0

为什么不直接使用本地sendmail? :) – 2012-08-17 01:11:03

+0

更好地使用新的CakeEmail类,而不是组件。这个错误是由于在调用send()之前没有设置主题,尽管你的代码显示你确实设置了它。这是致命的实际代码?你也要调用send()两次。 – Ceeram 2012-08-17 08:48:17

回答

0

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

public $components = array('Email'); 
+0

请问,如果它不适合你。 – 2012-08-17 04:18:44

+0

我的控制器中包含电子邮件组件。 – 2012-08-17 20:00:13

相关问题