i want to get read receipt of emails that we send by codeigniter emails.
i am not able to get how to use it in codeigniter mails.
i know we should use X-confirm reading but its not working in codeigniter.
public function formcomplete()
{
$appid = $this->uri->segment(3);
$datan = $this->product->fetchtransaction($appid);
$txnid = $datan[0]['txn_id'];
$email = $datan[0]['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$datanew = array(
'firstname' => $datan[0]['firstname'],
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$subject = "Complete Your Partially Filled Application-".$appid."";
$data['datan'] = $datanew;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->AddCustomHeader( "X-Confirm-Reading-To: notifications#mymail.com" );
$this->email->from('support#mail.com','Company Email');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
$baseurl = "https://www.getyourevisa.com/admin/application/view/";
$completeurl = $baseurl.$appid;
//redirect('admin/application/view/' . $appid);
echo ("<script LANGUAGE='JavaScript'>
window.alert('Form Complete Reminder Successfully Sent');
window.location.replace('$completeurl');
</script>");
}
i have used below line, but its not working, i think there should be some other way to write this code.
$this->email->AddCustomHeader( "X-Confirm-Reading-To: notifications#mymail.com" );
For CI version 3, it should be
$this->email->set_header('X-Confirm-Reading-To', 'name#email.com');
For CI version 4
$email->setHeader('X-Confirm-Reading-To', 'name#email.com');
Related
I've setup my email sender using outlook office365 with codeigniter 3. Below code works but sometimes it doesn't and I don't know why. Sometimes it will not work the first time I push my repo but when I tried it again, it works. I've logged the error below.
Error:
Failed to authenticate password. Error: <br />Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.<br />
Code:
public function send_mail($to_email = null, $name = '')
{
$config = array(
'protocol' => 'smtp',
'smtp_crypto' => 'tls',
'smtp_host' => 'smtp.office365.com',
'smtp_port' => 587
'smtp_user' => EMAIL_SENDER,
'smtp_pass' => EMAIL_SENDER_PASSWORD,
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE,
'newline' => "\r\n",
'crlf' => "\n",
'starttls' => true
);
$from_email = EMAIL_SENDER;
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($from_email, 'Power App');
$this->email->to($to_email);
$this->email->subject('Password Reset');
$this->email->set_crlf("\r\n");
$data["user"] = $to_email;
$data["name"] = $name;
$this->email->message($this->load->view('email/email_reset_password_template', $data, true));
//Send mail
if ($this->email->send())
return "Email sent successfully.";
else {
return $this->email->print_debugger();
}
}
UPDATE:
Its now always working when I use PHPMailer. Haven't really discover why its not always sending email using email library.
My codeigniter script will not send emails. I have tested sendmail on xampp with a native PHP email script and it works. This is definitely a problem with CI or my config. The send() function always returns false and the print_debugger() function is always blank. Am I doing something wrong?
<?php
$config = array(
'mailtype' => 'html',
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'myaccount#gmail.com',
'smtp_pass' => '#############',
'smtp_port' => '465'
);
$this->load->library('email', $config);
$this->email->from($this->stg['site_name']);
$this->email->to($this->input->post('email_address'));
$this->email->subject('Your Account Email Has Been Changed');
$data = array(
'activation_code' => $this->member->activation_code
);
$message = $this->load->view('emailTemplates/change_email', $data, true);
$this->email->message($message);
if(!$this->email->send()){
$this->template->overallHeader('Email Failed');
$data = array(
'title' => 'Email Sending Failed',
'message' => 'The system failed to dispatch the email message to your new email address. Because of this, the email address on your account has NOT been changed. '.$this->email->print_debugger()
);
$this->load->view('errorBody', $data);
} else {
//do stuff
}
I have also tried static strings instead of the form input variables as the to and from, etc.
I am working on booking app in codeigniter. I am stuck in email sending from localhost.
I am using gmail smtp for sending email. I am using email/booking_email.php view file as email template. But, When I run website page that contains email sending script in localhost, it keeps loading but email is not sent.
$email = "atomambition#gmail.com";
$name = "Wiyo HK";
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'atomambition#gmail.com',
'smtp_pass' => '********',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $email_config);
$this->email->from($email, $name);
$this->email->to($this->bookings_class->get_email());
$this->email->reply_to($email, $name);
$subject = 'This is Booking email from Wiyo HK';
$this->email->subject($subject);
$data = array('customer_name' => 'Avash Poudel');
$message = $this->load->view('email/booking_email', $data, TRUE);
$this->email->message($message);
echo $result = $this->email->send();
Localhost does not support sending emails directly unless configured.
In the localhost it does not work like this . For testing use mail() protocol on localhost and smtp on server.
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
Add this in $email_config.
After that you need to initialise your config array.
So write this $this->email->initialize($email_config);
Also use $this->email->print_debugger() to debug
I use CI library for sending HTML email through smtp. When i try to send from my computer, it send right HTML. but when i send it from server, why i get HTML tag. not formatted as html ? I already set 'mailtype' to 'html'.
I wonder why it work at my local but not at server. Is there any configuration in php ? or i should send email header or something?
public function index()
{
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'tls://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx',
'smtp_pass' => 'xxxx',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->load->library('email', $this->config->item('email'));
$this->email->set_newline("\r\n");
$this->email->from('xxxx', 'xxxx');
$this->email->to("xxxx");
$this->email->subject('Test Email');
$body = $this->load->view('welcome_message',null,TRUE);
$this->email->message($body);
if (!$this->email->send()){
echo 'fail to load email';
}
else {
echo 'success to send email';
}
}
Setting config options doesn't work unless you initialize them. Add this after your $config array:
$this->email->initialize($config);
Based on what I think you're trying to do:
$this->load->library('email', $this->config->item('email'));
should be
$this->load->library('email', $config);
Try and let us know.
I am trying to load a template into an email using Codeigniters email class, however I receive the email it is black, can anyone tell me why? Below is my code,
if($this->session->userdata('group_id') == '1') {
$data['key'] = $insertUser['activation_key'];
$data['name'] = $insertUser['name'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '*********',
'smtp_pass' => '********',
'mailtype' =>'html'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('no-reply#email.com', 'Email');
$this->email->to($insertUser['email']);
$this->email->subject('Your employers account');
$this->email->message($this->load->view('emails/signup', $data));
if (!$this->email->send())
show_error($this->email->print_debugger());
else
redirect('admin/users');
}
You need to add a third parameter to your call to $this->load->view, so the view is returned as a string:
$this->email->message($this->load->view('emails/signup', $data, true));
There is further information in the CI user guide - http://codeigniter.com/user_guide/general/views.html