我嘗試CakeEmail和我有問題。 我將代碼添加到了我的add函數中,類似於博客教程的add函數,但是當我添加一個項目時,它表示未定義的變量。如果我刪除了電子郵件代碼,它會起作用,如果我將它放入並刷新頁面中顯示的項目,但不會發送電子郵件。CakeEmail不能在添加功能
這裏是從功能的代碼:
public function add()
{
$this->set('isAddValid', false);
$this->set('addValidationErrors', false);
if ($this->request->is('post'))
{
// If the save is successful, close the dialog and display the success message
// Else, set the error flags.
if ($this->LocalClock->save($this->request->data))
{
$this->set('localClocks', $this->request->data);
$this->LocalClock->save($localClocks);
$this->set('isAddValid', true);
$this->set('addValidationErrors', false);
$email = new CakeEmail('smtp');
$email->from(array('[email protected]' => 'Local Clocks'));
$email->to('[email protected]');
$email->subject('New Local Clock Added');
$email->send('A new local clock has been added.');
CakeEmail::deliver('[email protected]', 'New local Clock', 'New Local Clock Added',
array('from' => '[email protected]'));
}
}
下面是在配置文件夾中的文件email.php(我只是複製從他們在那裏的默認文件的貼吧):
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => '[email protected]',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('[email protected]' => 'My Site'),
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $fast = array(
'from' => '[email protected]',
'sender' => null,
'to' => null,
'cc' => null,
'bcc' => null,
'replyTo' => null,
'readReceipt' => null,
'returnPath' => null,
'messageId' => true,
'subject' => null,
'message' => null,
'headers' => null,
'viewRender' => null,
'template' => false,
'layout' => false,
'viewVars' => null,
'attachments' => null,
'emailFormat' => null,
'transport' => 'Smtp',
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => true,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
任何幫助,將不勝感激
感謝
你歌廳哪些錯誤? – Dgo 2012-07-05 13:24:22
我收到通知(8):未定義的變量:localClocks, 奇怪的是它指定的錯誤在任何電子郵件代碼之前。 – RXC 2012-07-05 13:26:12
$ this-> Email - > _ debug = true;放入添加方法,並...看到你得到錯誤。 – Dgo 2012-07-05 13:30:55