问题
My codeigniter mail function was working fine in my local But the same code not working live and raise the error.
I think this error was password Mismatch. But I checked my password and password was right
here is my error message:
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--
I tried to change port number also but no use and here I will empty my password. But again I will say password was correct
Here is my code:
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());
}
}
Why it's raise the error in live?
回答1:
As you said the password is correct but it is saying password miss match because google restrict you to login to google mail.
To send the message you need to change some setting in your google account.
To do show first login to your google account and then go to https://myaccount.google.com/lesssecureapps here and turn on Allow less secure apps.
And go to https://accounts.google.com/b/0/displayunlockcaptcha here and allow the google access and then try again it will work.
来源:https://stackoverflow.com/questions/50187796/code-igniter-mail-function-working-well-in-my-local-but-not-in-live-and-raise-er