使用SMTP Codeigniter发送电子邮件 [英] Sending Email using SMTP codeigniter
问题描述
我正在尝试使用smtp codeigniter发送电子邮件。我正在使用的代码如下:
I am trying to send email using smtp codeigniter. The code I am using is as below:
public function notify_marketing(){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'myvalidemail@gmail.com',
'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('myvalidemail@gmail.com');
$this->email->to('validreceiptent@gmail.com');
$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());
}
}
但是我在响应中遇到以下错误。我尝试了该网站上的其他解决方案,但没有用。
However I am getting the following error in the response. I tried other solutions from this site but didn't work.
<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: <55d2ce42747f5@gmail.com>
Mime-Version: 1.0
谢谢。
推荐答案
代码完美。
您需要使用应用密码 > gmail,而不是gmail密码。请从gmail设置中设置应用程序密码,然后在此处输入密码。
You need to use Application password of gmail not the gmail password. Please set a application password from gmail settings and give the password here.
然后它将完美运行。请参阅 HERE
It will work perfectly then. See More from HERE
使用gmail设置应用密码的过程:
- 访问您的应用密码页面。可能会要求您登录Google帐户。
- 在底部,单击选择应用程序,然后选择您正在使用的应用程序。
- 单击选择设备,然后选择您正在使用的设备。
- 选择生成。
- 按照说明输入应用密码(16个字符的代码)
- 选择完成。
- Visit your App passwords page. You may be asked to sign in to your Google Account.
- At the bottom, click Select app and choose the app you’re using.
- Click Select device and choose the device you’re using.
- Select Generate.
- Follow the instructions to enter the App password (the 16 character code in the yellow bar) on your device.
- Select Done.
完成后,您将不会再看到该应用密码。但是,您将看到为其创建应用密码的应用和设备的列表。
Once you are finished, you’ll won’t see that App password code again. However, you will see a list of apps and devices you’ve created App passwords for.
这篇关于使用SMTP Codeigniter发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!