Codeigniter : Easy Send Mail by Codeigniter
autoload
1 |
$autoload['libraries'] = array('session','database','form_validation','email'); |
1 |
$autoload['helper'] = array('html','url','menu','form','file'); |
controller
email.php
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 |
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class email extends CI_Controller { public function __construct() { parent::__construct(); } public function index() { $this->load->view('form_mail'); } public function send() { $mailto=$this->input->post('mailto'); $mailsub=$this->input->post('mailsub'); $mailmessage=$this->input->post('mailmessage'); $this->email->from('devbanban@gmail.com'); $this->email->to($mailto); $datese = date('d/m/Y'); $this->email->subject('Subject : '.$mailsub); $this->email->message('Msg : '.$mailmessage.', date : '.$datese); //show Msg & date send if($this->email->send()){ $data['result']="Send mail OK"; $this->load->view('form_mail',$data); }else{ $data['result']="Not Send"; $this->load->view('form_mail',$data); } } } |
view form_mail.php
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 |
<!DOCTYPE html> <html> <head> <title>Test send mail by codeginter</title> </head> <body> <hr/> <?php echo @$result;?> <hr/> <form action="<?php echo site_url('email/send');?>" method="post"> <h4>::Mail Form::</h4> To <br /> <input type="text" name="mailto" required/> <br /> Subject <br /> <input type="text" name="mailsub" required /> <br /> Detail <br /> <textarea name="mailmessage" required></textarea> <br /> <button type="submit">Send</button> </form> </body> </html> |
Test on Server