I have been following this documentation here:
https://www.mailjet.com/docs/code/php/codeigniter
In my config folder I created a php file as shown above like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://in.mailjet.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'API key';
$config['smtp_pass'] = 'Pass Key';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "\r\n";
?>
But I am still getting the following error:
An Error Was Encountered
Non-existent class: Email
When I try to load the lib like this in a controller:
$this->load->library('email');
$this->email->from('your_sender#address.com', 'You');
$this->email->to('recipient#example.com');
$this->email->subject('My first email by Mailjet');
$this->email->message('Hello from Mailjet & CodeIgniter !');
$this->email->send();
Cheers.
You haven't got any file Email in System directory
Related
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();
}
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
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 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);
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();