can't send email with codeigniter

孤人 提交于 2020-06-04 03:01:31

问题


i try to send mail in codeigniter like this :

    public function send()  
  { 
    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'smtp.googlemail.com',
      'smtp_port' => 587,
      'smtp_user' => 'myemail@gmail.com',
      'smtp_pass' => 'mypass',
      'newlin'    => "\r\n"
    );
   $this->load->library('email', $config);  
   $this->email->set_newline("\r\n");  
   $this->email->from('myemail@gmail.com', 'Admin Re:Code');   
   $this->email->to('toanotheremail@gmail.com');   
   $this->email->subject('Percobaan email');   
   $this->email->message('Ini adalah email percobaan untuk Tutorial CodeIgniter: Mengirim Email via Gmail SMTP menggunakan Email Library CodeIgniter @ recodeku.blogspot.com');  
   if (!$this->email->send()) {  
    show_error($this->email->print_debugger());   
   }else{  
    echo 'Success to send email';   
   }  
  }

but i have some error :

220 smtp.googlemail.com ESMTP g15sm4364297pgu.52 - gsmtp

hello: 250-smtp.googlemail.com at your service, [182.253.163.55]

250-SIZE 35882577

250-8BITMIME

250-STARTTLS

250-ENHANCEDSTATUSCODES

250-PIPELINING

250-CHUNKING

250 SMTPUTF8

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. g15sm4364297pgu.52 - gsmtp Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

please help me.


回答1:


change

$config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'smtp.gmail.com', # Change this
  'smtp_crypto' => 'tls', # Add this
  'smtp_port' => 587,
  'smtp_user' => 'myemail@gmail.com',
  'smtp_pass' => 'mypass',
  'newlin'    => "\r\n"
);

And you're not using PHPMailer. Seems you're using email class of CI


If PHPMailer

require_once(APPPATH."third_party/phpmailer/PHPMailerAutoload.php");
$mail = new PHPMailer;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "aaa@gmail.com";
$mail->Password = "aaa";
$mail->CharSet = 'UTF-8';


来源:https://stackoverflow.com/questions/48212138/cant-send-email-with-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!