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
Related
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');
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 have used this several ways but can't seem to get it working. I am running it on live server.
I am using bigrock hosting and as per their document it says just use "localhost" as smtp host. Link
It says email sent but I get nothing..
public function index() {
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'localhost',
'smtp_port' => '587',
// Other way it say Email sent
//'smtp_host' => 'ssl://localhost',
//'smtp_port' => '465',
'smtp_user' => 'support#abc.com',
'smtp_pass' => 'sdfsfsdfsd'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('support#abc.com', 'ABC');
$this->email->to('abc#gmail.com');
$this->email->subject('Test');
$this->email->message('Success');
if ($this->email->send()) {
echo 'Email Sent';
} else {
show_error($this->email->print_debugger());
}
}
Thanks in advance.
This line: $this->email->to('abc#gmail'); make it 'abc#gmail.com' and make sure it is existing..If it still doesn't work, try a legit email from inside you email->from.
I am trying to send email using codeigniter.
<?php
class email_page extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$config = Array(
'protocol'=>'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'testmail#gmail.com',
'smtp_pass' => 'password'
);
$this->load->library('email', $config);
$this->email->set_newline('\r\n');
$this->email->from('testmail#gmail.com','Sender name');
$this->email->to('testmail#gmail.com');
$this->email->subject('Test mail');
$this->email->message('This is a test mail from codeigniter');
if($this->email->send()){
echo "Your mail was sent successfully!!!";
}
else{
show_error($this->email->print_debugger());
}
}
}
The page keeps on loading and does not give any result. The code looks fine to me. Are there any errors? Thanks
change your account settings here
https://www.google.com/settings/security/lesssecureapps
I myself found the answer.
$this->email->set_newline('\r\n');
Changed the above line to
$this->email->set_newline("\r\n");
I am not sure how this can happen.
i have found error, just change port to 25
function test(){
$config = Array(
'protocol'=>'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => '25',
'SMTPAuth' => true,
'smtp_user' => 'email#gmail.com',
'smtp_pass' => 'password'
);
$this->load->library('email', $config);
//$this->email->set_newline('\r\n');
$this->email->from('email#gmail.com','Sender name');
$this->email->to('email#micromerger.com');
$this->email->subject('Test mail');
$this->email->message('This is a test mail from codeigniter');
//print_r($this->email);exit;
if( ! $this->email->send()){
//print_r("234");exit;
echo "Your mail was sent successfully!!!";
}
else{
//print_r("345");exit;
show_error($this->email->print_debugger());
}
}
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.