Email 使用cakephp2发送电子邮件
我用cakephp2发送邮件时遇到问题,我知道我可以发送电子邮件,因为我配置了后缀,并且我可以用命令行或php发送电子邮件。那么,你能给我发一个cakephp2发送电子邮件的例子吗 这是错误消息 无效电子邮件:you@localhost 错误:发生内部错误 我也尝试过通过gmail使用ssl,但它也不起作用,这给了我一段非常艰难的时间 谢谢各位 顺便说一句,我正在尝试这个url的确切示例你的app/config/Email 类EmailConfig{ public$gmail=array “端口”=>“465”, “超时”=>“300”, '主机'=>'ssl://smtp.gmail.com', “用户名”=>“@gmail.com”, “密码”=>, “传输”=>“Smtp” } your file=app/controller/appController.php插入此函数Email 使用cakephp2发送电子邮件,email,cakephp-2.0,Email,Cakephp 2.0,我用cakephp2发送邮件时遇到问题,我知道我可以发送电子邮件,因为我配置了后缀,并且我可以用命令行或php发送电子邮件。那么,你能给我发一个cakephp2发送电子邮件的例子吗 这是错误消息 无效电子邮件:you@localhost 错误:发生内部错误 我也尝试过通过gmail使用ssl,但它也不起作用,这给了我一段非常艰难的时间 谢谢各位 顺便说一句,我正在尝试这个url的确切示例你的app/config/Email 类EmailConfig{ public$gmail=array “端口
public function sendEmail($type, $options){
try {
$Email = new CakeEmail($type);
$Email->config($options);
$Email->template = "email_confirmation";
$Email->emailFormat('html');
//$this->idCrudRash = $options;
$Email->send();
} catch (SocketException $e) {
die('Erro ao enviar email:'. $e->getMessage());
$this->log(sprintf('Erro ao enviar email: %s', $e->getMessage()));
}
}
对于用户:app/controller/contato.php
$options=array
“emailFormat”=>“html”,
'来自'=>数组
$config['email\u noanswer']=>$config['site\u name']
,
“主题”=>“确认地籍”,
'到'=>$this->请求->数据['User']['email'],
//'模板'=>'默认',
'模板'=>'电子邮件确认',
“视图变量”=>数组
“版面标题”=>“电子邮件确认”$配置['site_name'],
'name'=>$this->request->data['User']['name'],
'email'=>$this->request->data['User']['email'],
//“cpf”=>base64_encode$this->request->data['User']['cpf'],
'site_name'=>$config['site_name'],
,
;
$this->sendmail'gmail',$options 在您的email.php文件中,请删除默认的“from”值,它将覆盖您传递的参数
public $default = array(
'transport' => 'Mail',
'from' => 'you@localhost', // remove this line
...
);
为电子邮件模板创建布局和视图。并添加已发送的数据值。使用Gmail中有一个例子,它也失败了吗?您的电子邮件不包含域,例如.com,请尝试添加域。它已经在工作,我配置了我的postfix服务器并重定向到Gmail,Gmail的cakephp2示例对我不起作用。无论如何,谢谢你们=
In app/config/Email
public $smtp = array(
'transport' => 'Smtp',
'from' => array('no-reply@xyz.com' => 'no-reply@xyz.com'),
'host' => 'ssl://smtp.abc.com',
'port' => 465,
'timeout' => 30,
'username' => 'username',
'password' => 'password',
'client' => null,
'log' => false,
);
In Your Controller
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
public function index()
{
$this->layout = 'layout';
$this->set('title', "Title");
if ($this->request->is('Post')) {
if (!empty($this->request->data)) {
if ($this->Modal->Save($this->request->data)) {
$to = 'test@anc.com';
$subject = 'Your_subject';
$message = $this->request->data;
if ($this->sendmail($to, $subject, $message)) {
echo"sent";die;
}
} else {
echo"wrong";die;
}
}
}
}
public function sendmail($to = null, $subject = '', $messages = null, $ccParam = null, $from = null, $reply = null, $path = null, $file_name = null)
{
$this->layout = false;
$this->render(false);
$name = $messages['Modalname']['name'];
$email = $messages['Modalname']['email'];
$Email = new CakeEmail();
$Email->config('smtp');
$Email->viewVars(array('name' => $name, 'email' => $email));
$Email->template('comman_email_template', 'comman_email_template');
return $Email->emailFormat('html')
->from(array('no-reply@xyz.com' => 'no-reply@xyz.com'))
->to($to)
->subject($subject)
->send();
}