以下是我用来发送电子邮件的代码: - 这是我的email.php文件
class EmailConfig {
public $default = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'my@gmail.com',
'password' => 'secret',
'transport' => 'Smtp'
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('admin@example.com' => 'Project Name'),
'host' => 'smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'test@gmail.com',
'password' => 'secret',
'client' => null,
'log' => false,
'tls' => true
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
function i have created in App controller:-
function sendEmail($email, $subject, $body){
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$send=$Email->from(array('test@gmail.com'=>'testing Apps'))
->to($email)
->subject($subject)
->emailFormat('html')
->send($body);
if($send){
return "sent";
}else {
return "error";
}
}
注册时我可以通过gmail,ymail电子邮件发送邮件,但是当我通过我的公司域名电子邮件注册而不是通过错误
CORE / Cake / Network / Email / MailTransport.php第51行→MailTransport-> _mail(字符串,字符串,字符串,字符串,null) CORE / Cake / Network / Email / CakeEmail.php第1122行→MailTransport->发送(CakeEmail) APP / Controller / AppController.php第66行→CakeEmail->发送(字符串) APP / Controller / UsersController.php第254行→AppController-> sendEmail(字符串,字符串,字符串) [内部功能]→UsersController-> register() CORE / Cake / Controller / Controller.php第490行→ReflectionMethod-> invokeArgs(UsersController,array) CORE / Cake / Routing / Dispatcher.php第185行→Controller-> invokeAction(CakeRequest) CORE / Cake / Routing / Dispatcher.php第160行→Dispatcher-> _invoke(UsersController,CakeRequest,CakeResponse) APP / webroot / index.php第108行→Dispatcher-> dispatch(CakeRequest,CakeResponse)