【问题标题】:Codeigniter emailer not workingCodeigniter 电子邮件不起作用
【发布时间】: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>&nbsp;</td><td>".$this->input->post('sender_name')."</td></tr><tr><td>&nbsp;</td><td>".$this->input->post('sender_email')."</td></tr><tr><td>&nbsp;</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-&gt;email-&gt;initialize($config); 即可解决问题,但为什么呢?

【问题讨论】:

  • 这可能对你有帮助:stackoverflow.com/questions/17982704/…
  • @Mr.Web 是的,我之前确实从该链接中获得了解决方案。但我想知道为什么默认设置不起作用。 CI 中的任何更新导致了这种情况?
  • 对不起,我不知道。我现在使用的是 v 3.0,我必须检查一下,因为我到现在都没有使用它。

标签: php codeigniter email


【解决方案1】:

试试下面的代码。

$config = array();
$config['useragent']           = "CodeIgniter";
$config['mailpath']            = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol']            = "smtp";
$config['smtp_host']           = "localhost";
$config['smtp_port']           = "25";
$config['mailtype'] = 'html';
$config['charset']  = 'utf-8';
$config['newline']  = "\r\n";
$config['wordwrap'] = TRUE;

$this->load->library('email');

$this->email->initialize($config);

$this->email->message = "Your Message";
$this->email->subject("Message Subject");
$this->email->from("user@gmail.com");
$this->email->to("admin@gmail.com");
$this->email->send();

【讨论】:

    猜你喜欢
    • 2014-07-05
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 2016-07-15
    • 2013-07-08
    • 2018-09-21
    • 2017-11-30
    相关资源
    最近更新 更多