我正在尝试 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('me@example.com' => 'Local Clocks'));
$email->to('you@example.com');
$email->subject('New Local Clock Added');
$email->send('A new local clock has been added.');
CakeEmail::deliver('you@example.com', 'New local Clock', 'New Local Clock Added',
array('from' => 'localhost@localhost'));
}
}
这是配置文件夹中的 email.php 文件(我只是从他们那里的默认文件中复制粘贴它):
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('site@localhost' => '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' => 'you@localhost',
'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',
);
}
任何帮助,将不胜感激
谢谢