使用CodeIgniter 3.1.10发送电子邮件

时间:2019-08-12 08:03:24

标签: php codeigniter

我想使用codeigniter发送电子邮件,我知道如何在互联网上做到这一点。但是当我编写代码时,电子邮件不会发送给人们。

使用codeigniter 3.1.10

private function _sendEmail(){
  $config = [
    'mailtype'  => 'html',
    'charset'   => 'utf-8',
    'protocol'  => 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com',
    'smtp_user' => '****',
    'smtp_pass' => '****',
    'smtp_port' => 465,
    'crlf'      => "\r\n"
  ];
  $this->load->library('email',$config);
  $this->email->from('vcopadangpariaman@gmail.com','VCO Padang Pariaman');
  $this->email->to('taufikleon44@gmail.com');
  $this->email->subject('Testing');
  $this->email->message("hallo");
  if($this->email->send()){
    return true;
  }else {
    echo $this->email->print_debugger();
  }
}

我想发送电子邮件至taufikleon44@gmail.com

1 个答案:

答案 0 :(得分:1)

这可能是由于SMTP身份验证中提供的用户名和密码错误或邮件服务器防火墙中阻止了SMTP端口。

如果您使用的是Gmail帐户,请检查此链接并关闭“允许安全性较低的应用程序”。

以下是网址:https://myaccount.google.com/lesssecureapps

然后尝试再次发送电子邮件。

我已经更新了您的代码并立即检查:

private function _sendEmail() {
        $config = [
            'mailtype' => 'html',
            'charset' => 'utf-8',
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.gmail.com',
            'smtp_user' => '****',
            'smtp_pass' => '****',
            'smtp_port' => '465',
            'smtp_timeout' => '20',
            'validation' => TRUE,
            'newline' => "\r\n"
        ];
        $this->load->library('email', $config);
        $this->email->initialize($config);
        $this->email->from('vcopadangpariaman@gmail.com', 'VCO Padang Pariaman');
         $this->email->to('taufikleon44@gmail.com');
        $this->email->subject('Testing');
        $this->email->message("hallo");
        if ($this->email->send()) {
            return true;
        } else {
            echo $this->email->print_debugger();
        }
    }