无法通过 codeigniter 发送电子邮件

can not send email by codeigniter

我已经使用下面的代码发送电子邮件,但在本地和实时服务器上不起作用?

//this function sends a confirmation email to the user while registration
public function send_email($email,$message,$subject) {
     // configuration
    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'example@gmail.com', 
      'smtp_pass' => 'password', 
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->from('example@gmail.com');
    $this->email->to($email);
    $this->email->subject($subject);
    $this->email->message($message);
    $result = $this->email->send();
    $this->email->clear();
    return ($result);
}

试试这些设置:

// The mail sending protocol.
$config['protocol'] = 'smtp';
// SMTP Server Address for Gmail.
$config['smtp_host'] = ssl://smtp.googlemail.com
// SMTP Port - the port that you is required
$config['smtp_port'] = 465;
// SMTP Username like. (abc@gmail.com)
$config['smtp_user'] = $sender_email;
// SMTP Password like (abc***##)
$config['smtp_pass'] = $user_password;
// Load email library and passing configured values to email library
$this->load->library('email', $config);
// Sender email address
$this->email->from($sender_email, $username);
// Receiver email address.for single email
$this->email->to($receiver_email);
//send multiple email
$this->email->to(abc@gmail.com,xyz@gmail.com,jkl@gmail.com);
// Subject of email
$this->email->subject($subject);
// Message in email
$this->email->message($message);
// It returns boolean TRUE or FALSE based on success or failure
$this->email->send(); 

您使用的是 gmail smtp 吗?我以前遇到过同样的问题。然后我在我的 google 帐户

上激活允许安全性较低的应用

然后就可以了