Mar
16

Send Email from your Gmail account Using Codeigniter.

Author ZeeShaN    Category Codeigniter, PHP, Web Development     Tags ,

Codeigniter provides many built in helpers and libraries which help us to perform lot of functionality for developing projects. Here a simple email library make us able to send email using our Gmail account living in CI environment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?
class Send_Email extends Controller
{
function Send_Email()
 
{
	parent::Controller();
}
function index()
{
  $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'email_address@gmail.com', // change it to yours
  'smtp_pass' => 'your_password', // change it to yours
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);
 
  $this->load->library('email', $config);
  $this->email->set_newline("\r\n");
  $this->email->from('your_email@domain.com'); // change it to yours
  $this->email->to('your_email@domain.com'); // change it to yours
  $this->email->subject('Email using Gmail.');
  $this->email->message('Working fine ! !');
 
  if($this->email->send())
 {
  echo 'Email sent.';
 }
 else
{
 show_error($this->email->print_debugger());
}
}
}?>

Add To Facebook Stumble This Digg This Add To Del.icio.us Add To Reddit Add To Yahoo Add To Twitter


Written by ZeeShaN

ZeeShaN RasooL is a web developer who loves to work in latest technologies to create more interactive dynamic and beautiful web pages.


  • Would someone tell me the modifications required to send the mail from the hosting server?

    December 24 2011
    CommentsLike
    • rashid

      how to convert website which is developing using codeigniter and php in english language to another language.

      December 15 2011
      CommentsLike
      • rashid

        The following error are occur
        1.A PHP Error was encountered

        Severity: Warning

        Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?)

        Filename: libraries/Email.php

        Line Number: 1652

        2.A PHP Error was encountered

        Severity: Warning

        Message: fwrite() expects parameter 1 to be resource, boolean given

        Filename: libraries/Email.php

        3.The following SMTP error was encountered: 142484584 Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?
        Unable to send data: AUTH LOGIN
        Failed to send AUTH LOGIN command. Error:
        Unable to send data: MAIL FROM:

        from:

        The following SMTP error was encountered:
        Unable to send data: RCPT TO:

        to:

        The following SMTP error was encountered:
        Unable to send data: DATA

        December 14 2011
        CommentsLike

        • Thanks.
          Nice tutorial

          May 17 2011
          CommentsLike
          • Nazmul Hossain

            Thanks …….. nice tutorial

            January 23 2011
            CommentsLike
            • wahyu

              thanks for share ….

              September 20 2010
              CommentsLike

              • [...] This post was mentioned on Twitter by 99_Points. 99_Points said: Send Email from your Gmail account Using Codeigniter. http://bit.ly/agJht8 [...]

                April 14 2010
                CommentsLike
                • Gewa

                  Thank you Zeeshan for sharign this idea

                  April 12 2010
                  CommentsLike








                  Enter your Email:

                  Click Here for Popular

                  Who I Am

                  Zeeshan Rasool

                  Software Engineer - PHP
                  Lahore - Pakistan

                  zeeshan(@)99points.info
                  Skype: zeeshan-rasool
                  gTalk: zishan.rasool85

                  Categories

                  Tags

                  Comments