Home arrow PHP arrow Page 2 - Working with the Email Class in Code Igniter

Sending email with Code Igniter - PHP

Unless you’ve already built a PHP toolkit that lets you develop web applications by reusing its components, the best way to create complex PHP programs quickly is by means of a third-party framework, such as Code Igniter (http://codegniter.com). This package will let you build robust object-based PHP applications in literally minutes, thanks to its extremely friendly interface. So, if you’re interested in learning how to put this framework to work for you, start reading this article now!

  1. Working with the Email Class in Code Igniter
  2. Sending email with Code Igniter
  3. Defining a simple view file
  4. Sending email messages via an HTML form
By: Alejandro Gervasio
Rating: starstarstarstarstar / 7
October 01, 2008

print this article



True to form, sending email through Code Igniter is a process reduced to feeding its email class with some typical parameters, such the email’s sender, the message’s subject, the corresponding text, and so forth. Of course, this has to be done by using the MVC pattern, therefore I’m going to define a controller class that sends email in a truly simple fashion.

The signature of this controller is listed below. Take a look at it, please:

class Email extends Controller{

function Email(){

// load controller parent




function index(){

// set email class parameters

$this->email->from('me@domain.com','Alejandro Gervasio');




$this->email->subject('Testing email class');

$this->email->message('How are you, buddy?');

$data['title']='Sending email...';

$data['header']='Sending email now...';

$data['message']=$this->email->send()?'Message was sent successfully!':'Error sending email!';




As you can see, the above “Email” controller class presents a structure similar to the examples developed in previous tutorials. First, its constructor loads the corresponding email class via a loader object, so it can be used at a later time.

Then, the “index()” method sets a few conventional parameters, which are used to send the email message, and finally dispatches the message via the “send()” method. Also, you should notice that the controller uses a view to display an error message or a simple confirmation of whether or not the email has been successfully sent. That was really simple to follow, wasn’t it?

Now that you have learned how to use Code Igniter to send email messages very easily, it’s time to see how to code the previous view file, which will print on screen an indicative message.

To learn how this view file will be created, please click on the link that appears below and keep up reading.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: