How to send email with CodeIgniter

How to send email with CodeIgniter


How to send email with CodeIgniter
How to send email with CodeIgniter
Today I have solve this task share with you codeigniter Mail Function Send a Mail I am  First time Implementing MVC Structure.  Following Code. Session Storage



View.html

<form action="<?php echo base_url('index.php/email/mysend_mail'); ?>" method="post">
Please, enter e-mail: <input type="text" name="e-mail"><input type="submit" name="submit" value="Submit">
</form>

Controller

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

class Email extends CI_Controller {

  public function __construct(){
    parent::__construct();
    $this->load->helper('url');
  }

public function index()
{

$this->load->view('header');
    $this->load->view('email_form');
    $this->load->view('footer');
}
  
  public function mysend_mail(){
    $this->load->helper('url');

    if (!isset($_POST['e-mail'])){
      //redirect if no parameter e-mail
      redirect(base_url());
    };

    //load email helper
    $this->load->helper('email');
    //load email library
    $this->load->library('email');
    
    //read parameters from $_POST using input class
    $email = $this->input->post('e-mail',true);    
  
    // check is email addrress valid or no
    if (valid_email($email)){  
      // compose email
      $this->email->from($email , 'xxxxx');
      $this->email->to($email); 
      $this->email->subject('My First CodeIgniter Email Example');
      $this->email->message('CodeIgniter Email Example App!');  
      
      // try send mail ant if not able print debug
      if ( ! $this->email->send())
      {
        $data['message'] ="Email not sent \n".$this->email->print_debugger();      
        $this->load->view('header');
        $this->load->view('message',$data);
        $this->load->view('footer');

      }
         // successfull message
        $data['message'] ="Email was successfully sent to $email";
      
        $this->load->view('header');
        $this->load->view('message',$data);
        $this->load->view('footer');
    } else {

      $data['message'] ="Email address ($email) is not correct. Please <a href=".base_url().">try again</a>";
      
      $this->load->view('header');
      $this->load->view('message',$data);
      $this->load->view('footer');
    }

  }
  
  public function info(){
    phpinfo();
  }
    
}

How to send email with CodeIgniter Dev2Tricks 5 of 5
How to send email with CodeIgniter How to send email with CodeIgniter Today I have solve this task share with you codeigniter Mail...

Share this

Related Posts

Previous
Next Post »

Xolo Offer