Unable to send other domain mail id using codeigniter - 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();

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.

Getting blank attachment for generated pdf in codeigniter by mPdf

Here is my function.I m generating a pdf and trying to mail it. I have checked my email library which is working fine but gives blank attachment for generated pdf.
function voucherEmail()
{
$this->load->library('m_pdf');
ob_start();
$day = date('d');
$year = date('Y');
$month = date('F');
echo "Hello World Today is $month $day, $year";
$html = ob_get_contents();
ob_end_clean();
$this->m_pdf->pdf->WriteHTML(($html));
$content = $this->m_pdf->pdf->Output('','S');
$filename = "giftVoucher.pdf";
$config = array();
$config['useragent'] = "CodeIgniter";
$config['protocol'] = "sendmail";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = "html";
$config['charset'] = "iso-8859-1";
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('voucher#theholidaysclubs.com', 'The Holidays Club:Gift Voucher');
$this->email->to('shikhachauhan862#gmail.com');
$this->email->subject('The Holidays Club:Gift Voucher');
$this->email->attach($content,'attachment',$filename,'application/pdf');
$this->email->send();
}
Can someone please where I am going wrong

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

Why isn't my email function working in 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";

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