Skip to main content

Sending Emails with Codeigniter Framework

Codeigniter supported inbuilt Email library class which simplify the email sending process. To send email we need to do some configuration , need to load email library.codeigniter supports Multiple Protocols, Mail, Sendmail, and SMTP, Multiple recipients, CC and BCCs,HTML or Plain text email, Attachments ,Word wrapping and many more.


Lets start with Codeigniter email  configurations. Here I have used gmail as smtp server.

$this->load->library('email');

// Email configuration 
$config = Array(

    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'senders_email_address',
    'smtp_pass' => '********',   //Password of senders email
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);

Now, we can send the email with above configurations.

$this->load->library('email', $config);
$this->email->set_newline("\r\n");

$this->email->from('senders_email', 'name_of_the_sender');
$this->email->to('reciever's_mail_address'); 
$this->email->cc(''); 
$this->email->bcc(''); 

$this->email->subject('subject_of_the_mail');
$this->email->message('message_body');
$this->email->send();

Comments

Popular posts from this blog

Uploading Images with CodeIgniter Framework

      Images can be uploaded into a specific folder in the server by checking whether a folder with given name is exists or not. If exists, that folder can be deleted and uploaded the desired images. And also in some cases we may need to create "Thumbnails" (Small images) of the original image. Steps for uploading images with thumbnails are given below. 1. Path  to the folder to upload images should be specified. If the folder is in the root folder name of that folder can be used as the path. $path = 'images'; Or else, a sub folder within the images folder can be given as follows, $folder_name = $ad_id; $path = 'images/'.$folder_name; 2. Checking whether a folder exists with the given name and if exists deleting it with its sub folders. if(file_exists($path)){        $path = rtrim($path, '/') . '/'; $items = glob($path . '*'); foreach($items as $item)                { ...

Inserting Records into the Database Table with Codeigniter framework

Codeigniter framework provides easier way to insert records into a given database table. We need to assign the values into respective attributes using and array.  Then we can insert whatever the record using a single line of code. SQL statements are handled by the framework itself. $record = array( 'field_1' => value_1 'field_2' => value_2, 'field_3' => value_3,                 'field_4' => value_4 ); $this->db->insert('name_of_the_table', $record);