How to send mail using CodeIgniter and smtp

Leave a Comment

Send mail using codeIgniter and smtp



Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file.In the past, I have used the email helper extensively in combination with sendmail, however for a new project I was required to route e-mail through a third-party SMTP server, in this case Gmail. I used the following code:
 function sendMail()
 {
     $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx@gmail.com', // change it to yours
    'smtp_pass' => 'xxx', // change it to yours
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
  );

       $message = '';
       $this->load->library('email', $config);
       $this->email->set_newline("\r\n");  
       $this->email->from('xxx@gmail.com'); // change it to yours
       $this->email->to('xxx@gmail.com');// change it to yours
       $this->email->subject('CodeIgniter and smtp');
       $this->email->message('send mail using CodeIgniter and smtp');
     if($this->email->send())
     {
       echo 'Email sent.';
     }
     else
     {
      show_error($this->email->print_debugger());
     }

 }







Helpful links


How to send mail using CodeIgniter.

Leave a Comment

Send E-mail using codeIgniter.


Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file. CodeIgniter's Email Class supports the following features:

  • Multiple Protocols: 
  • Mail, Sendmail, and SMTP Multiple recipients 
  • CC and BCCs 
  • HTML or Plaintext email 
  • Attachments 
  • Word wrapping 
  • Priorities 
  • BCC Batch Mode, enabling large email lists to be broken into small BCC batches. 
  • Email Debugging tools
Here is a basic example demonstrating how you might send HTML email.
So let's start with controller.

Controller Name : email.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Email extends CI_Controller {
 
 function __construct(){

  parent::__construct();
  //load the  library
  $this->load->library('email');
 }

 function send_mail(){
 
  $this->email->from('mohitj475@gmail.com', 'Mohit');
  $this->email->to('mohitj475@gmail.com');
  
  $this->email->subject('mail send demonstration');
  $this->email->message('this is testing');
  
  $this->email->send();
  
  echo $this->email->print_debugger();
 }
}



If you run above code then you will get output like this




Explanation : In controller's constructor method first we load email library so we can use library function.After that we created send_mail function in to we use library function.

Email Function Reference


$this->email->from()

Sets the email address and name of the person sending the email:
$this->email->from('mohitj475@gmail.com', 'Mohit');
$this->email->to()

Sets the email address(s) of the recipient(s). Can be a single email, a comma-delimited list or an array:
$this->email->to('mohitj475@gmail.com');
$this->email->to('one@example.com, two@example.com, three@example.com');
$list = array('one@example.com', 'two@example.com', 'three@example.com');

$this->email->to($list);
$this->email->subject()

Sets the email subject:
$this->email->subject('mail send demonstration');
$this->email->message()

Sets the email message body:
 $this->email->message('this is testing');
$this->email->send()

The Email sending function. Returns boolean TRUE or FALSE based on success or failure, enabling it to be used conditionally:
if ( ! $this->email->send())
{
    // Generate error
}
For function more Visit this link





Helpful links


CodeIgniter From Scratch : CRUD

Leave a Comment

Basic CRUD With Codeigniter



If you are totally new to the codeigniter experience and you can't still understand the way that you can create a CRUD, this codeigniter CRUD tutorial is just for you.We'll review how to easily create, read, update, and delete records using CI's active-records class.

So, We will do it this process in 4 stage

Stage 1 : In this stage we will setup a directory and database.

Stage 2 : In this stage we will Select all database from the database and show into the view.

Stage 3 : In this stage we will Edit and Update Data from the database

Stage 4 : In this stage we will see how to delete data from the database

let's start with Stage 1

How to Setup CodeIgniter on local xampp server with screenshots

Leave a Comment

Codelgniter install Step By Step Tutorial for beginners:

What is CodeIgniter?

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you're a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you're tired of ponderously large and thoroughly undocumented frameworks, then CodeIgniter might be a good fit.

How To install CodeIgniter?

In our local server with step by step with screenshots.

Step 1 : Download codeIgniter from Here

Step 2 : After downloaded codelgniter extract in your server root directory i.e. your htdocs folder

Step 3 : After that rename that folder into your project name In my case its folder name is CI you can rename whatever you want

Step 4 : After that open your browser and run http://localhost/CI/

Your Page get look like this as seen below



And here you done your codelgniter is finally setup Now you start with its coding...enjoy...





Helpful links


Powered by Blogger.