Sending Emails THrough Codeigniter PHP -


i need send mail after submitting form. below code able error is. redirecting same page.below controller. if use email function inserting database if use mail not inserting.

function addparents() {     $this->load->library('form_validation');     $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');       $this->form_validation->set_rules('first_name','first name','required|alpha');     $this->form_validation->set_rules('last_name','last name','required|alpha');     $this->form_validation->set_rules('mobile_number','mobile number','required|is_numeric|max_length[10]');     $this->form_validation->set_rules('email_list','email_list','required|valid_email');     $this->form_validation->set_rules('message','message');              if($this->form_validation->run()== false)         {                 $data['mainpage']='profile';         $data['mode']='parents';         $this->load->view('profile',$data);     }      else{         $result=$this->category_model->send_mail($this->input->post('email'));         if($result)         {             $this -> profile_model -> insertparents();             $this->flash->success('<h2>parents added successfully!</h2>');             redirect('profile');         }         else         {             $this->flash->success('<h2 style="color:red">sorry ! message sending failed</h2>');             redirect('profile');         }     }  } 

this model sending email :

function send_mail($email) {     $name=$this->input->post('full_name');     $mobileno=$this->input->post('mobile');      $messagess1=$this->input->post('message');     $this->email->set_mailtype("html");      $messagess = "<html>\n";     $messagess .= "<body>     <div>dear ,<div>     <p>please find below information user sent you.</p><br> <br>     <table collspan=\"5\">         <tr>             <td>name</td>             <td>: </td>             <td><strong>".$name."</strong></td>         </tr>     <tr>         <td>e-mail</td>         <td>:</td>         <td><strong>".$email."</strong>     </tr>      <tr>         <td>mobile no</td>         <td>:</td>         <td><strong>".$mobileno." </strong>     </tr>      <tr>         <td>message</td>         <td>:</td>         <td><strong>".$messagess1."</strong>     </tr>     </table>     <br><br><p>thanks &amp; warm regards,</p><p>".$name."</p>";      $messagess .= "</body>\n";     $this->email->from($email, "kids2play");     $this->email->to("ashalatha.cse76@gmail.com");      $this->email->message($messagess);      if($this->email->send()){         return true;     }     else          return false; } 

here complete code you.

    function addparents()     {     $this->load->library('form_validation');     $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');       $this->form_validation->set_rules('first_name','first name','required|alpha');     $this->form_validation->set_rules('last_name','last name','required|alpha');     $this->form_validation->set_rules('mobile_number','mobile number','required|is_numeric|max_length[10]');     $this->form_validation->set_rules('email_list','email_list','required|valid_email');     $this->form_validation->set_rules('message','message');              if($this->form_validation->run()== false)         {                 $data['mainpage']='profile';         $data['mode']='parents';         $this->load->view('profile',$data);     }      else{         $name=$this->input->post('full_name');         $mobileno=$this->input->post('mobile');          $messagess1=$this->input->post('message');         $messagess = "<html>\n";         $messagess .= "<body>         <div>dear ,<div>         <p>please find below information user sent you.</p><br> <br>         <table collspan=\"5\">             <tr>                 <td>name</td>                 <td>: </td>                 <td><strong>".$name."</strong></td>             </tr>         <tr>             <td>e-mail</td>             <td>:</td>             <td><strong>".$email."</strong>         </tr>          <tr>             <td>mobile no</td>             <td>:</td>             <td><strong>".$mobileno." </strong>         </tr>          <tr>             <td>message</td>             <td>:</td>             <td><strong>".$messagess1."</strong>         </tr>         </table>         <br><br><p>thanks &amp; warm regards,</p><p>".$name."</p>";          $messagess .= "</body>\n";          $to = 'ashalatha.cse76@gmail.com';         $subject = 'thanks &amp; warm regard';         $result=$this->sendmail($to,$subject,$messagess);         if($result)         {             $this -> profile_model -> insertparents();             $this->flash->success('<h2>parents added successfully!</h2>');             redirect('profile');         }         else         {             $this->flash->success('<h2 style="color:red">sorry ! message sending failed</h2>');             redirect('profile');         }     }  }  function sendmail($to,$subject,$fullmsg){ $config = array(        'mailtype' => 'html',         'protocol' => 'smtp',         'smtp_host' => 'ssl://smtp.gmail.com',         'smtp_port' => 465,         'smtp_user' => 'ashalatha.cse76@gmail.com', // change yours         'smtp_pass' => 'your gmail password', // change yours         'mailtype' => 'html',         'charset' => 'iso-8859-1',         'wordwrap' => true       );           $this->load->library('email', $config);         $this->email->set_newline("\r\n");         $this->email->from(''); // change yours         $this->email->to($to);// change yours         $this->email->subject($subject);         $this->email->message($fullmsg);         if($this->email->send())        {           return true;        }        else       {        show_error($this->email->print_debugger());       }      } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -