2012-08-17 123 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

相關問題