I’m trying out CakeEmail and I am having a problem.
I added the code into my add function, similar to the blog tutorial’s add function, but when I add an item it says undefined variable. If I remove the email code, it works, if I leave it in and refresh the page the item shows up but no email.
Here is the code from the function:
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'));
}
}
Here is the email.php file in the config folder (i just copied an pasted it from the default file they had in there):
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',
);
}
Any help would be appreciated
Thanks
I found out that the answer required me to add another setting to the email.php file.
I created a gmail account so I can use the email feature.
The code is pretty simple:
And in the add() function: