我得到"未知的电子邮件配置&#g;' "错误,在尝试使用Cakephp发送电子邮件时,是因为我是从localhost(xampp)发送的吗?
if($this->User->save($this->request->data)){
$message='Click on the link below to complete registration ';
$confirmation_link='www.sitename.com/users/verify/t:'.$hash.'/n:'.$this->data['User']['username'].'';
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');
$email->Email->from = 'myemail@gmail.com';
$email->Email->to=$this->data['User']['email'];
$email->Email->subject = 'Confirm Registration';
$email->Email->smtpOptions = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myemail@gmail.com',
'password' => 'mypassword',
'transport' => 'Smtp'
);
$email->send($message . " " . $confirmation_link);
$this->Session->setFlash(__('you should activate your account'));
}
}
答案 0 :(得分:1)
要使用new CakeEmail('gmail')
,您必须在配置文件(/Config/email.php)中配置gmail
,例如:
public $gmail = [
'transport' => 'Mail',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
];
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html
new CakeEmail('gmail')
会读取您的gmail
配置,您无需在应用中进行配置。
如果您在应用程序中进行了所有配置,也许您想使用new CakeEmail();