猿问

使用 CodeIgniter 3.1.10 发送电子邮件

我想使用 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


心有法竹
浏览 204回答 1
1回答

UYOU

这可能是因为 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();        }    }
随时随地看视频慕课网APP
我要回答