我尝试在codeigniter中发送邮件,如下所示:
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';
}
}
但我有一些错误:
220 smtp.googlemail.com ESMTP g15sm4364297pgu.52 - gsmtp
你好:250-smtp.googlemail.com为您服务,[182.253.163.55]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
250-PIPELINING
250 CHUNKING
250 SMTPUTF8
无法发送AUTH LOGIN命令。错误:530 5.7.0必须首先发出STARTTLS命令。 g15sm4364297pgu.52 - gsmtp无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。
请帮帮我。
答案 0 :(得分:2)
变化
$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"
);
你没有使用PHPMailer。好像你正在使用email class of CI
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';