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' => '[email protected]',
'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]');
$this->email->to('[email protected]');
$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: <[email protected]>
Mime-Version: 1.0
Thank you in advance.
Sending an Email The subject() and message() function is used to set the subject and message of the email. $this->email->from('[email protected]', 'Your Name'); $this->email->to('[email protected]'); $this->email->subject('Email Test'); $this->email->message('Testing the email class.
To start, create a Mailtrap account and login. Click on Add Inbox , fill in the inbox name and click on Save . Now, click on the gear icon to see the credentials needed to send email with Mailtrap. On the page where you were redirected, click on Integrations list and choose CodeIgniter to view the configuration code.
'smtp_user' => '[email protected]', the email address that will be used as the sender when sending emails. This should be a valid email address that exists on the server. 'smtp_pass' => '12345! ', the password to the specified smtp user email.
The code is perfect.
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.
It will work perfectly then. See More from HERE
Process to setting up a app password in gmail:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With