Codeigniter Email Class Library
Codeigniter Email Class Library – Email class library provide various functions that are used to send email. It can be done by protocal. $this->load->library(’email’); is used to load the library. Here in this tutorial, we are going to explain how to use email class library.
Codeigniter email class library | Load | Example
Let us understand how file email class works in codeigniter with examples.
Load codeigniter email class library
How to load email class library:
$this->load->library('email'); |
Functions:-
There are following functions available in email class library. Now let us go through one by one to understand.
- 1. Sending email
- 2. Setting email preferences
1. Sending email
EXAMPLE
Here is simple example of sending email.
Sending email in codeigniter example:-
//Controller public function sendmail() { $this->load->library('email'); $this->load->view('library/email_view'); $from = $this->email->from('sonukr321@gmail', 'sonu kumar'); $to = $this->email->to('sharmasonukr321@gmail.com'); $cc = $this->email->cc('abc@gmail.com'); $bcc = $this->email->bcc('xyz@gmail.com'); $subject = $this->email->subject('Email Test'); $message = $this->email->message('Testing the email class.'); if($this->email->send($from, $to, $cc, $bcc, $subject, $message)) { echo "sent succesfully"; } else { echo "unable to send"; } } |
2. Setting email preferences
EXAMPLE
Here is simple example of setting email preferences.
Setting email preferences in codeigniter example:-
//Controller $config['protocol'] = 'sendmail'; $config['mailtype'] = 'text'; $config['smtp_timeout'] = '5'; $config['mailpath'] = '/usr/sbin/sendmail'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = TRUE; $this->email->initialize($config); |
There are 21 different preferences availables.
Class reference
There are many types of class reference in email class library.
1. From
from($from[$name = ''[$return_path = NULL]])
This function is used to set email address and name of sender.
2. Reply to
reply_to($replyto[$name = ''])
This function is used to set reply to address.
3. To
to($to)
We use this function to set email address of reciever. address can be single or multiple both.
4. CC
cc($cc)
We use this function to set multiple email address of reciever.
5. Subject
subject($subject)
This function is used to set email subject.
6. Message
message($body)
This function is used to set email message body.
7. Set alt message
set_alt_message($str)
This function is used to set alternative email message body.
8. Set header
set_header($header, $value)
This function is used to add additional header.
9. Clear
clear([$clear_attachments = FALSE])
This function is used to clear all attachment files.
10. Send
send([$auto_clear = TRUE])
This method is used to sending the email.
11. Attachment
attach($filename[$disposition = ''[$newname = NULL[$mime = '']]])
We use this function to add multiple attachment files.
12. Print debugger
print_debugger([$include = array('headers', 'subject', 'body')])
By using this function we can print any type of error in email class.
Advertisements