【发布时间】:2015-11-03 13:11:16
【问题描述】:
$this->load->library('email');
// set email data
$this->email->from($this->input->post('sender_email'), $this->input->post('sender_name'));
$this -> email -> set_mailtype("html");
$this->email->to('');
$this->email->reply_to($this->input->post('sender_email'), $this->input->post('sender_name'));
$this->email->subject('From: '.$this->input->post('sender_name'));
$this->email->message("<table><tr><td> </td><td>".$this->input->post('sender_name')."</td></tr><tr><td> </td><td>".$this->input->post('sender_email')."</td></tr><tr><td> </td><td>".$this->input->post('phone')."</td></tr><tr><td>Message: </td><td>".$this->input->post('message')."</td></tr></table>");
$this->email->send();
// create a view named "succes_view" and load it at the end
redirect('contact?email_succ=1');
exit();
这是我用来从 CI 中的表单发送电子邮件的代码,它仅在我同时使用 SMTP 登录时才有效。
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'myemail@example.com';
$config['smtp_pass'] = 'emailpassword';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
在加载库后立即使用此代码可以解决问题。但是一直在工作但突然停止的默认代码有什么问题?
更新:仅添加这一行 $this->email->initialize($config); 即可解决问题,但为什么呢?
【问题讨论】:
-
@Mr.Web 是的,我之前确实从该链接中获得了解决方案。但我想知道为什么默认设置不起作用。 CI 中的任何更新导致了这种情况?
-
对不起,我不知道。我现在使用的是 v 3.0,我必须检查一下,因为我到现在都没有使用它。
标签: php codeigniter email