If I submit to reset the new password to my email, CodeIgniter is not sending mail. But it's returning a message that Password Reset Email Sent. So it doesn't trigger an error.
I'm using CodeIgniter 2.1.4 and IonAuth 2.5.2
$config['use_ci_email'] = TRUE;
I already set this config to TRUE, and still not sending mail.
Not change anything in 'ion_auth.php'. file as it is like :
$config['use_ci_email'] = FALSE; // Send Email using the builtin CI email class, if false it will return the code and the identity
$config['email_config'] = array(
'mailtype' => 'html',
);
and then 'Auth.php' which is controller file in change some code which is like :
if ($forgotten)
{
// if there were no errors
// $this->session->set_flashdata('message', $this->ion_auth->messages());
// redirect("auth/login"); //we should display a confirmation page here instead of the login page
$config = [
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html'
];
$data = array(
'identity'=>$forgotten['identity'],
'forgotten_password_code' => $forgotten['forgotten_password_code'],
);
$this->load->library('email');
$this->email->initialize($config);
$this->load->helpers('url');
$this->email->set_newline("\r\n");
$this->email->from('xxx');
$this->email->to("xxx");
$this->email->subject("forgot password");
$body = $this->load->view('auth/email/forgot_password.tpl.php',$data,TRUE);
$this->email->message($body);
if ($this->email->send()) {
$this->session->set_flashdata('success','Email Send sucessfully');
return redirect('auth/login');
}
else {
echo "Email not send .....";
show_error($this->email->print_debugger());
}
}
else
{
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("auth/forgot_password");
}
I use config in codeigniter
application/config/email.php
$config['protocol'] = 'mail';
$config['wordwrap'] = false;
$config['mailtype'] = 'html';
application/config/autoload.php
$autoload['libraries'] = array('lang','template', 'email','form_validation','session','encrypt','pagination','upload','database' );
In controller
$this->email->from(MAIL,MAIL);
$this->email->to($mailto);
$this->email->subject($text_subject);
$this->email->message($this->load->view('email/template_email',$data,TRUE));
$this->email->send();
Related
Failed to authenticate password. Error: 535 Incorrect authentication
data Unable to send email uenter code heresing PHP SMTP. Your
server might not be configured to send mail using this method.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.******.com',
'smtp_port' => 587,
'smtp_user' => 'tracker#******.com',
'smtp_pass' => '7Wj{S******KU{',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = 'Hiii';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// $this->load->library('email');
$this->email->from('tracker#******.com'); // change it to yours
$this->email->to($usremail);// change it to yours
$this->email->cc('');
// $this->email->bcc('gobinath#******.com');
$this->email->subject('hi');
$this->email->message($message);
$mailsucc = $this->email->send();
if ($mailsucc) {
echo "suc";
exit();
}else{
$de = $this->email->print_debugger();
print_r($de);
exit();
}
I've been looking for a while, and finally I get it. I hope this works for you too.
Define your timezone:
php timezone
date_default_timezone_set('America/Bogota');
Set up your email account to allow IMAP access, and allow email to be used in less secure applications
less secure apps
IMAP Access
Set up your mail server with codeigniter:
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = 'xxxxxxxxxx#gmail.com';
$config['smtp_pass'] = 'xxxxxxxxxxx';
$config['smtp_port'] = 465; (465/587)
$config['charset'] = 'utf-8';
$config['crlf'] = "\r\n";
$config['smtp_crypto'] = 'ssl'; (SSL/TSL)
$this->email->initialize($config);
$this->email->set_newline("\r\n");
Prepare your mail to send:
$this->email->from('xxxxxxxxxx#gmail.com', 'ANY-NAME');
$this->email->to('yyyy#yyy.yyy');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if($this->email->send()){
echo "sent";
}
else{
echo $this->email->print_debugger();
}
Hello everyone, I'm currently working on a CodeIgniter application in which user will be able to create their own accounts,etc.
I'm trying to create a function to recover password in case is lost or forgotten.
Here is my code:
public function admin_recover(){
$this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[7]|valid_email');
if($this->form_validation->run() == FALSE){
//Load View Into Template
$this->template->load('admin', 'login', 'users/recover');
} else {
//Get Post Data
$email = $this->input->post('email');
$password = $this->input->post('password');
$user_email = $this->User_model->get_list();
if($user_email){
$user_email_data = array(
'email' => true
);
///////// Sending email
// Configure email library
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$config['crlf'] = '\r\n';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['priority']=1;
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.gmail.com';
$config['smtp_port']='25';
$config['smtp_timeout']='30';
$config['smtp_user']='kuaf1998#gmail.com';
$config['smtp_pass']='mypassword';
$config['newline']="\r\n";
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('no-reply#socialgeek.com', 'Social Geek');
$this->email->to('kebin1421#hotmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
if($this->email->send())
$this->session->set_flashdata("success","Email sent successfully.");
else
$this->session->set_flashdata("error","Error in sending Email.");
echo $this->email->print_debugger();
//////////////
}
}
}
I'm using the gmail smtp service to send emails from my localhost but I'm still unable to make it happen. Any idea how can I fix this?
I already did some changes on(I'm using xampp) the ini file which is found on my xampp>php>php.ini
When I go to the view, I get this error:
Thanks for helping.
Try to use these configuration settings below and let me know if it works for you.
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'user#gmail.com',
'smtp_pass' => 'yourpassword',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
I have created a controller and made a test function in the controller to test if the email is sent or not.
I checked with different email addresses, but didn't succeed. This is my code example:
public function sendmail() {
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$user_id = 1;
$name = 'Mark Alan';
$this->email->set_newline("\r\n");
$this->email->from('info#domainname.com', "Test Name");
$this->email->to('test#domainname.com');
$this->email->subject('Test Mail');
$this->email->message('This is a test message');
$this->email->send();
echo $this->email->print_debugger();
}
With Codeigniter (assuming you have auto-loaded the email library) you can either set an email preference in a config file, named email.php and these preferences are loaded automatically from there. It could look like:
// Setting Email Preferences
$config['useragent'] = 'CodeIgniter'; // Mail engine switcher: 'CodeIgniter' or could be 'PHPMailer'
$config['protocol'] = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
or like in your example, you can set them manually, but need to initialize it, so don't forget this line after defining your $config[] array:
$this->email->initialize($config);
Try this code:
function sendMail()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com', //Your Host
'smtp_port' => 465, // Add 25 port if you sending from your smtp mail server
'smtp_user' => 'xxx#gmail.com', // change it to yours, server email
'smtp_pass' => 'xxx', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#gmail.com'); // change it to yours
$this->email->to('xxx#gmail.com');// change it to yours
$this->email->subject('Resume from JobsBuddy for your Job posting');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
Note: Please add your smtp port and your smtp email account detail.
Hello I am using codeigniter controller to send emails, after getting data from the db. But the problem is when the email reaches $this->email->initialize($config); while debugging it crashes with the error
Severity: Notice
Message: Undefined property : Invoice::$email
Line Number: 563
Everything looks pretty fine, and I normally use this email functionality in a lot of places. But I cannot figure out the error.
Here is the code in the controller.
public function sendReminderForUnpaidInvoice() {
//fetch tha data from the database
$this->load->model('invoice_page');
$foo = $this->invoice_page->get();
$result = json_decode(json_encode($foo), true);
foreach ($foo as $result){
$this->load->library('../controllers/payment');
$resultMangoPay = $this->payment->getMangopayPayinForTheInvoiceMail($result->rf_reference);
$totalAmount = ($result->gross_amount) + ($result->type_related_amount) ;
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'support#aurorax.co';
$config['smtp_pass'] = '#########';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config); // line 563
$this->email->from('support#aurorax.co', 'aurora exchange');
$this->email->to($result->Email);
$this->email->subject('Repayment invoice');
$this->email->message(
'Hello '.$result->Fullname.'.'."\n"
.'Here is a invoice for the next upcoming payment. '."\n"."\n"
.'Payment should be done by bank transfer to the information provided below'."\n"
.'Name :'.$resultMangoPay['OwnerName']
.'IBAN :'.$resultMangoPay['IBAN']
);
$returnvalue = $this->email->send();
if(!$returnvalue) {
return false;
} else {
// will do something here later
}
$this->email->clear(TRUE);
}
}
You cannot load a codeigniter library or a model after you have loaded a controller, it breaks that way, if you load your email library and your model first and then load your payment controller, it should work as how it should.
Try initializing the library using the array.
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_timeout' => '7',
'smtp_user' => 'support#aurorax.co',
'smtp_pass' => '#########',
'charset' => 'utf-8',
'newline' => "\r\n",
'mailtype' => 'text',
'validation' => TRUE
);
$this->load->library('email', $config);
I was trying sent email using PHP CodeIgniter framework. after i uploaded that file into my browser it didn't show me any error. it said:"Your email was sent successfully". But i didn't get any email in my email account. I could not figure out what was the problem. I am using CodeIgniter version 2.1.3. can anyone please help me. I am new in PHP. Thank You.
Here is my code:
<?php
class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->library('email');
$this->email->from('hasib32#gmail.com', 'Hasan Hasibul');
$this->email->to('riar32#gmail.com');
$this->email->subject('email test');
$this->email->message('testing the email class. email sent');
if($this->email->send()){
echo"Your email was sent successfully";
}else
{
show_error($this->email->print_debugger());
}
}
}
You can try this:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '...#gmail.com',
'smtp_pass' => '....',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$email_setting = array('mailtype'=>'html');
$this->email->initialize($email_setting);
$email_body ="<div>hello world</div>";
$this->email->from('...#gmail.com', 'shahriar');
$list = array('...#gmail.com');
$this->email->to($list);
$this->email->subject('Testing Email');
$this->email->message($email_body);
$this->email->send();
echo $this->email->print_debugger();
}
this works for me. happy coding :)
Its because you don't have mail server setup in your localhost. You can either setup it or you can use your gmail account to send your mail like this-
$config = Array(
‘protocol’ => ‘smtp’,
‘smtp_host’ => ‘ssl://smtp.googlemail.com’,
‘smtp_port’ => 465,
‘smtp_user’ => ‘myusername#gmail.com’,
‘smtp_pass’ => ‘mypassword’,
);
$this->load->library('email', $config);
$this->email->from('hasib32#gmail.com', 'Hasan Hasibul');
$this->email->to('riar32#gmail.com');
$this->email->subject('email test');
$this->email->message('testing the email class. email sent');
if($this->email->send()){
echo"Your email was sent successfully";
} else {
show_error($this->email->print_debugger());
}
Check e-mail server in the mail queue. probably waiting.