Codeigniter: Override variable in auto-loaded config file - codeigniter

I have the following:
config/email.php
$config['protocol'] = 'smtp';
$config['smtp_host'] = "xxxxxx";
$config['smtp_user'] = "xxxxxx";
$config['smtp_pass'] = "xxxxxx";
$config['smtp_port'] = xx;
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
So in most cases, I'm sending HTML with plain-text alternative emails. This config works perfectly.
Now in one special case, I'm wanting to send a plain-text email so I need to override that setting to:$config['mailtype'] = 'text';
How can I do that? I tried specifying a new config array and loading the library again but it still sends as HTML:
$email_config = Array(
'mailtype' => 'text'
);
$this->load->library('email', $email_config);

I think you need to call initialize when you don't load from a config file.
$this->email->initialize($email_config);

You should use:
$config['mailtype'] = 'text';
$this->email->initialize($config);

Related

Error while sending email with attachment through Codeigniter

I am trying to send an email with the attachment through Codeigniter. The problem is that it attaches the file at the run time but just sends the specified content ignoring the attachment.
I have tried uploading it in 'uploads' folder and send it along with content but it sends the msg only and displays the error mentioned below
class Email_send extends CI_Controller {
public function send()
{
$file_data = $this->upload_file();
$to = $this->input->post('from'); // User email pass here
$subject = 'Offer from Saremco Impex';
$from = 'myemail';// Pass here your mail id
$emailContent = '<!DOCTYPE><html><head></head><body><table width="600px" style="border:1px solid #cccccc;margin: auto;border-spacing:0;"><tr><td style="background:#ffa500;padding-left:3%"><!--<img src="http://localhost/crud/assets/logo/eoffice_logo.png" width="300px" vspace=10 />--></td></tr>';
$emailContent .= '<tr><td style="height:20px"></td></tr>';
$emailContent .= $this->input->post('message'); // Post message available here
$emailContent .= '<tr><td style="height:20px"></td></tr>';
$emailContent .= "<tr><td style='background:#ffa500;color: #999999;padding: 2%;text-align: center;font-size: 13px;'><p style='margin-top:1px;'><a href='http://saremcoimpex.com/' target='_blank' style='text-decoration:none;color: #60d2ff;'>www.saremcoimpex.com</a></p></td></tr></table></body></html>";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 60;
$config['smtp_user'] = 'myusername';
$config['smtp_pass'] = 'mypass';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = FALSE; // bool whether to validate email or not
//$file_path = 'uploads/' . $file_name;
$this->load->library('email', $config);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->from($from);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($emailContent);
$this->email->attach($file_data['full_path']);
$this->email->send();
/* $this->session->set_flashdata('success','Mail has been sent successfully');
return redirect(base_url().'index.php/user/');*/
echo $this->email->print_debugger();
}
function upload_file()
{
$config['upload_path'] = './uploads';
$config['allowed_types'] = 'doc|docx|pdf';
$this->load->library('upload', $config);
if($this->upload->do_upload('resume'))
{
return $this->upload->data();
}
else
{
return $this->upload->display_errors();
}
}
}
Message: Illegal string offset 'full_path' Thats the error
Technically that should work. Maybe your uploads are not working properly, and if display_errors() returns a string, that would be the cause of your error.

Unable to send other domain mail id using codeigniter

<?php
`unable to send other domain mail id using codeigniter`
$this->load->library('email'); <BR>
$to = 'otherdomain#example.org';<BR>
$from = $this->input->post('Email');<BR>
$fromName = $this->input->post('Name');<BR>
$mailSubject = 'Contact Request Submitted by '.$fromName;<BR>
$message = $this->input->post('Message');<BR>
$this->email->from($from, 'name'); <Br>
$this->email->to($to); <Br>
$this->email->subject('Email Test'); <Br>
$this->email->message('Testing the email class.');<BR>
$this->email->send();
?>
Try this it will work...
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.domain.com';
$config['smtp_port'] = '587';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'domain email here';
$config['smtp_pass'] = 'email password here';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('email here', 'Email Name');
$this->email->to('email to');
$this->email->subject('subject here');
$this->email->message('message here');
$this->email->send();

send email by using codeigniter library via server

i want to send email using SMTP protocol Via server.my server is host gator.
enter image description here
You need configure user and pass in configs
specify your problem better
thanks... i done it with same code...
just change the port then its working....
here is code
function do_email($msg=NULL, $sub=NULL, $to=NULL, $from=NULL){
$this->load->library('email');
$config = array();
$config['protocol']='smtp';
$config['smtp_host']='localhost';
$config['smtp_port']='587';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($from, $system_name);
$this->email->to($to);
$this->email->subject($sub);
$this->email->message($msg);
$email = $this->email->send();
}

Codeigniter email issue, I'm struggling to send email one after another

I am tring to send mails through codeigniter email class. Following is a method from my controller :
$config['protocol'] = 'mail';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('xxx#yyy.zzz');
for($i=0; $i< count($data); $i++)
{
$this->email->to($data[$i]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();
}
$admin_data = $this->admin_model->get_admin_detail();
$this->email->to($admin_data[0]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();
I am getting mails using my script in for loop. But then it shows HTTP 500 Internal Server Error. And I did not get mail to my admin email.
Expected : emails to users using for loop [it's working]
and one email [after for loop ends] to admin mail.
Thanks.!
Try this...
$this->load->library('email');
$config['protocol'] = 'mail';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
for($i=0; $i< count($data); $i++)
{
$this->email->clear();
$this->email->from('xxx#yyy.zzz');
$this->email->to($data[$i]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();
}
$admin_data = $this->admin_model->get_admin_detail();
$this->email->clear();
$this->email->from('xxx#yyy.zzz');
$this->email->to($admin_data[0]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();

Call to a member function from() on a non-object in my mail settings

I wrote this code to sent a mail in codeigniter
$this->mailconfig['mailtype']='text';
$this->load->library('email', $this->mailconfig);
$this->email->from('ajithm#qburst.com','Tony');
$this->email->to($this->mail);
$this->email->subject('PASSWORD');
$this->email->message('Your password is:' . $password);
$this->email->send();
But i got a error as PHP Fatal error: Call to a member function from() on a non-object
Not sure if you can pass the config when loading the email library. In the docs this is a bit different:
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('ajithm#qburst.com','Tony');
$this->email->to($this->mail);
$this->email->subject('PASSWORD');
$this->email->message('Your password is:' . $password);
$this->email->send();

Resources