0
votes

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' => '[email protected]',
      'smtp_pass' => 'mypass',
      'newlin'    => "\r\n"
    );
   $this->load->library('email', $config);  
   $this->email->set_newline("\r\n");  
   $this->email->from('[email protected]', 'Admin Re:Code');   
   $this->email->to('[email protected]');   
   $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
I don't know how you're meant to do it in CI, but you need to tell it to use STARTTLS encryption before it will allow you to authenticate. - Synchro
if you google the error you get heaps of answers: google.pt/… - Vickel

1 Answers

2
votes

change

$config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'smtp.gmail.com', # Change this
  'smtp_crypto' => 'tls', # Add this
  'smtp_port' => 587,
  'smtp_user' => '[email protected]',
  '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 = "[email protected]";
$mail->Password = "aaa";
$mail->CharSet = 'UTF-8';