php - 代码点火器邮件功能在我的本地运行良好但在现场运行并引发错误
问题描述
我的 codeigniter 邮件功能在我的本地运行良好但相同的代码无法实时运行并引发错误。
我认为这个错误是密码不匹配。但是我检查了我的密码并且密码是正确的
这是我的错误信息:
An Error Was Encountered
220 smtp.googlemail.com ESMTP s189-v6sm30071511pgc.39 - gsmtp
hello: 250-smtp.googlemail.com at your service, [181.224.149.217]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to authenticate password. Error: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 s189-v6sm30071511pgc.39 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Sat, 5 May 2018 14:39:51 +0530
To: tprakash11121996@gmail.com
From: "MyWebsite" <tprakashkce@gmail.com>
Return-Path: <tprakashkce@gmail.com>
Subject: =?utf-8?Q?=48=6F=77=20=74=6F=20=73=65=6E=64=20=65=6D=61=69=6C=20=76=69=61?= =?utf-8?Q?=20=53=4D=54=50=20=73=65=72=76=65=72=20=69=6E=20=43=6F=64=65=49?= =?utf-8?Q?=67=6E=69=74=65=72?=
Reply-To: "tprakashkce@gmail.com" <tprakashkce@gmail.com>
X-Sender: tprakashkce@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5aed74df89302@gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5aed74df89342"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_5aed74df89342
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Billed Patient DetailsDear Sir/madam, We are attached billed patient files
in this mail
--B_ALT_5aed74df89342
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
=3Ch1=3EBilled Patient Details=3C/h1=3E=3Cp=3EDear Sir/madam,=3Cbr=3E We ar=
e attached billed patient files in this mail=3C/p=3E
--B_ALT_5aed74df89342--
我也尝试更改端口号但没有用,在这里我将清空我的密码。但我再说一遍密码是正确的
这是我的代码:
public function sendMail(){
$this->load->library('email');
//SMTP & mail configuration
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'example@gmail.com',
'smtp_pass' => '*********',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
//Email content
$htmlContent = '<h1>Billed Patient Details</h1>';
$htmlContent .= '<p>Dear Sir/madam,<br> We are attached billed patient files in this mail</p>';
$this->email->to('tprakash11121996@gmail.com');
$this->email->from('tprakashkce@gmail.com','MyWebsite');
$this->email->subject('How to send email via SMTP server in CodeIgniter');
$this->email->message($htmlContent);
if($this->email->send()){
echo "Mail Succesfully send";
}
else{
show_error($this->email->print_debugger());
}
}
为什么它会在现场引发错误?
解决方案
正如你所说的密码是正确的,但它说密码不匹配,因为谷歌限制你登录谷歌邮件。
要发送消息,您需要更改 Google 帐户中的一些设置。
要显示首先登录到您的 google 帐户,然后在此处转到https://myaccount.google.com/lesssecureapps并打开Allow less secure apps。
并在此处访问https://accounts.google.com/b/0/displayunlockcaptcha并允许谷歌访问,然后再试一次它会起作用。
推荐阅读
- assembly - x86-64 汇编:理解四字操作码 `shlq`
- c++ - 将引用绑定到指针的语法是什么?(各种)
- svg - 使用 max 函数在 svg 中使用计算值
- text - 替换 .txt 文件中的特定字符
- java - 第二个主类在 Maven 构建期间覆盖第一个主类
- python - 将返回一维数组的函数应用于 numpy 数组的所有元素
- yaml - VSTS YAML 管道 - 将项目存储库作为现有构建定义的参数传递
- sql-server-2008 - 基于某些共享列创建标识符/计数器并基于其他列分开
- image - 如何创建单个 openshift 模板来创建多个 pod(不同的应用程序)?
- mysql - MySQL,数月计算不同的元素