I have written following code to send email in CI. jquery ->
function emailToPatient(url,base)
{
$.ajax({
url: base+"Home/send_mail",
type: 'POST',
async: false,
data: 'path="'+url+'"&e-mail=some_email@test.com',
success: function(data) {
alert(data);
},
error: function(e) {
}
});
}
In controller ->
public function send_mail(){
$this->load->library('email');
$config = Array(
'useragent' => 'CodeIgniter',
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'myemail@gmail.com', // change it to yours
'smtp_pass' => 'mypassword', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->email->initialize($config);
$this->email->from('myemail@gmail.com', "Admin Team");
$this->email->to("myemail@gmail.com");
$this->email->subject("This is test subject line");
$this->email->message("Mail sent test message...");
if($this->email->send()){
echo $data['message'] = "Mail sent...";
}
else
echo $data['message'] = "Sorry Unable to send email...";
echo $this->email->print_debugger();
}
In jquery alert it is showing following error :
Sorry Unable to send email...220 smtp.gmail.com ESMTP xz5sm11454554pbb.12 - gsmtp
<br /><pre>hello: 250-smtp.gmail.com at your service, [49.248.7.114]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH OAUTHBEARER
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
</pre>Failed to authenticate password. Error: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/answer/14257 xz5sm11454554pbb.12 - gsmtp
<br />Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.<br /><pre>User-Agent: CodeIgniter
Date: Fri, 2 Oct 2015 12:46:22 +0200
From: "Admin Team" <myemail@gmail.com>
Return-Path: <myemail@gmail.com>
To: myemail2@gmail.com
Subject: =?iso-8859-1?Q?=54=68=69=73=20=69=73=20=74=65=73=74=20=73=75=62=6A=65=63?= =?iso-8859-1?Q?=74=20=6C=69=6E=65?=
Reply-To: "myemail@gmail.com" <myemail@gmail.com>
X-Sender: myemail@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <560e607e1aff7@gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_560e607e1aff7"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_560e607e1aff7
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Mail sent test message...
--B_ALT_560e607e1aff7
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Mail sent test message...
--B_ALT_560e607e1aff7--</pre>
In php.ini I did following setting SMTP = smtp.gmail.com
smtp_port = 465
I am using WAMP server Pls suggest solution for above issue.