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
Related
I am trying to use image url instead of base64. i kindof figured a way how to get images out of the editor and save it inside the directory, but i am trying to insert it into database. i get this error.
Object of class DOMElement could not be converted to string
below i have added the store function inside my controller
public function store(Request $request)
{
//
$data = $request->all();
if (!$request->has('published')) {
$data['published'] = 0;
} else {
$data['published'] = 1;
}
if (!$request->has('featured')) {
$data['featured'] = 0;
} else {
$data['featured'] = 1;
}
$img = null;
if ($request->hasfile('title_img')) {
$image = $request->file('title_img');
$name = time() . '.' . $image->getClientOriginalExtension();
$image->move(public_path() . '/uploads/blogs/', $name);
$img = '/uploads/blogs/' . $name;
}
/* summernote */
$detail=$data['description'];
$dom = new \DomDocument();
$dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$images = $dom->getElementsByTagName('img');
foreach($images as $k => $img){
$data = $img->getAttribute('src');
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
$image_name= "/uploads/summernote/" . time().$k.'.jpeg';
$path = public_path() . $image_name;
file_put_contents($path, $data);
$img->removeAttribute('src');
$img->setAttribute('src', $image_name);
}
$detail = $dom->saveHTML();
/* summernote */
$data['title_img'] = $img;
$data['user_id'] = auth()->user()->id;
$title = $data['title'];
$data['slug'] = Str::slug($title);
auth()->user()->posts()->create($data);
return Redirect::route('admin.blog.index')->withSuccess('Whoopie!! New Blog Added!');
}
I hope i can get some help regarding this. Thanks in advance
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.
<?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();
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();
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();