我正在尝试使用 smtp codeigniter 发送电子邮件。我正在使用的代码如下:
public function notify_marketing(){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected] /cdn-cgi/l/email-protection',
'smtp_pass' => '*******',//my valid email password
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->email->initialize($config);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('[email protected] /cdn-cgi/l/email-protection');
$this->email->to('[email protected] /cdn-cgi/l/email-protection');
$this->email->subject('My Subject');
$this->email->message('Hello there');
if($this->email->send())
{
$this->session->set_flashdata("success","Email sent.");
}
else
{
show_error($this->email->print_debugger());
}
}
但是我在响应中收到以下错误。我尝试了该网站的其他解决方案,但没有成功。
<div id="exception_error">
<h1><span class="type">An Error Was Encountered [ 500 ]</span></h1>
<div class="content">
<p><p>220 smtp.googlemail.com ESMTP bv4sm16669443pbb.86 - gsmtp
<br /><pre>hello: 250-smtp.googlemail.com at your service, [110.44.127.179]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
</pre>lang:email_smtp_auth_pw<br />lang:email_send_failure_smtp<br /><pre>User-Agent: CodeIgniter
Date: Tue, 18 Aug 2015 12:03:42 +0545
From: <********@gmail.com>
Return-Path: <********@gmail.com>
To: *******@gmail.com
Subject: =?iso-8859-1?Q?My_Subject?=
Reply-To: "********@gmail.com" <*********@gmail.com>
X-Sender: *******@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected] /cdn-cgi/l/email-protection>
Mime-Version: 1.0
先感谢您。
代码很完美。
你需要使用申请密码gmail 的密码不是 gmail 的密码。请从 Gmail 设置中设置应用程序密码,并在此处提供密码。
然后它就会完美地工作。查看更多来自HERE https://www.linkedin.com/groups/Simple-Tricks-send-email-from-109912.S.5959285043661660163?trk=groups_search_item_list-0-b-ttl
在 Gmail 中设置应用程序密码的过程:
- 访问您的应用程序密码页面 https://security.google.com/settings/security/apppasswords。系统可能会要求您登录您的 Google 帐户。
- 在底部,单击选择应用程序并选择您正在使用的应用程序。
- 单击选择设备并选择您正在使用的设备。
- 选择生成。
- 按照说明在您的设备上输入应用程序密码(黄色栏中的 16 个字符代码)。
- 选择完成。
完成后,您将不会再看到该应用程序密码。但是,您将看到已为其创建应用程序密码的应用程序和设备的列表。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)