Why isn't my email function working in CodeIgniter - codeigniter

This mail function is not working.
In the code below, the $tomail and $frommail parameters are correct, but the mail isn't getting to my Gmail account.
$this->load->library('email');
$config['mailtype'] = 'html';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->to($to);
$this->email->from($from);
$this->email->cc($cc);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
if ( ! $this->email->send())
{
echo $this->email->print_debugger();

Try this one:
$this->load->library('email');
$config['mailtype'] = 'html';
$config['protocol'] = 'sendmail';
$this->email->initialize($config);
$this->email->from('yourmailid', 'Admin');
$this->email->to($email);
$this->email->subject('hello world');
$this->email->message($body);
if($this->email->send())
echo "email send";

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();

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();

codeigniter mail not sending

This the function in my controller, which is called:
public function sendContact()
{
$this->load->model('main_model');
$to_email = $this->main_model->get_account_email();
$from_email = $this->input->post('email');
$name = $this->input->post('name');
$message = $this->input->post('message');
$this->load->library('email');
$this->email->set_mailtype("html");
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject('Contact');
$this->email->message($message);
$this->email->send();
}
I get no errors, but the mail isn't incomming in the mailbox.
When i do a print, everything seems to be fine..
In another controller, this code is working fine, my host supports mailing..
I've been looking so long to it, what an I overlooking?

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