Friday 5 October 2012

Sending Email in Codeigniter


Here iam describing about sending mail using smtp server in codeigniter.:- Below is the controller code:-


function Index()
    {
    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'youraccount@gmail.com',
      'smtp_pass' => 'password'
       
    );
     
    $this->load->library('email', $config);    //loading email libraray
    $this->email->set_newline("\r\n"); /* for some reason it is needed */
     
    $this->email->from('name@gmail.com', 'Aditya Lesmana Test');
    $this->email->to('name@gmail.com');
    $this->email->subject('This is an email test');
    $this->email->message('haai');
     
    if($this->email->send())
    {
      echo 'Your email was sent, success';
    }
    else
    {
      show_error($this->email->print_debugger());
    }
     
    }

No comments:

Post a Comment