简体   繁体   English

SMTP + Gmail错误:邮件未发送

[英]SMTP + Gmail error : mail not send

I'm trying to send email. 我正在尝试发送电子邮件。 This is the code that I have written. 这是我编写的代码。

config['protocol']      = 'smtp';
$config['smtp_host']    = 'ssl://smtp.googlemail.com';
$config['smtp_port']    = '465';
$config['smtp_user']    = 'mymail@gmail.com';
$config['smtp_pass']    = '123';
$config['mailtype']     = 'html';
$config['charset']      = 'iso-8859-1';
$config['wordwrap']     = TRUE;    
$config['newline']      = "\r\n";

Here's the error i'm getting: 这是我得到的错误:

The following SMTP error was encountered: 110 Connection timed outUnable to send email using PHP SMTP. 遇到以下SMTP错误:110连接超时无法使用PHP SMTP发送电子邮件。 Your server might not be configured to send mail using this method. 您的服务器可能未配置为使用此方法发送邮件。

 User-Agent: 用户代理:\nCodeIgniter  

\n\n Date: Wed, 24 May 2017 14:39:24 +0530 From: "SMEC" <contact@labs.info> Return-Path: <contact@labs.info> Reply-To: <training@labs.org> To: test00@gmail.com Subject: =?ISO-8859-1?Q?=53=4D=45=43=4C=61=62=73=20=2D=20=43=41=52=45=45=52=20=49?= =?ISO-8859-1?Q?=4E=20=43=4F=52=45=20=49=4E=44=55=53=54=52=49=45=53=21=21?= X-Sender: contact@labs.info X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: &ltgt; Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_59254dc4bc79e" This is a multi-part message in MIME format. Your email application may not support this format.

The below configuration works perfectly for me even with Gmail. 即使使用Gmail,以下配置也非常适合我。

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'example@gmail.com';
$config['smtp_pass'] ='yourmailpassword';
$config['mailtype'] = 'html';

$this->load->library('email', $config);

$this->email->set_newline("\r\n");

$this->email->from('from@gmail.com', 'TEST MAIL');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);

$this->email->send();

Don't forget to enable less trusted app access in your Gmail account. 不要忘记在Gmail帐户中启用不太受信任的应用程序访问。 I was able to send both simple text emails and emails with HTML templates and images with above configuration without any problem. 通过上述配置,我可以发送简单的文本电子邮件以及带有HTML模板和图像的电子邮件,而不会出现任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM