Welcome Guest, Not a member yet? Register   Sign In
Send email from a post
#3

(This post was last modified: 09-27-2017, 02:44 PM by ciadvantage.)

In your 'items/view', you can embed a snippet html for the required form.  Just use the ajax post to submit the user data such as
Code:
//js snippet to submit form

var submit_data = $('form').serialize(); // assume you only have this custom form embedded otherwise you may need id for it
var url = '/Somecontroller/submit_user_data'; //follows Controller/action format  
$.post(url,submit_data,function(data){
//your action code here for what being as data return
// i.e
 if(data.success=1){
  console.log('maybe some message on the form ' + data.message);
 }
},'json');

Then your Somecontroller class may have function like this
function submit_userdata(){
 $user_data= $this->input->post(NULL,TRUE); //$user_data is an ass. array that reflects on what you have at
                                            // input form such as username, useremail,content_submitted so on
 //note this is quick dirty suggestion, you may need to sanitize the user input
 $bSaveStatus=$this->save_userdata($user_data); //user_data is an array and assume you have save_userdata as another func in this
                                                //controller and it returns boolean TRUE upon success
 if($bSaveStatus){
     $bSendStatus=$this->send_email($user_data); // easy to set your own email function
                                                  //either by helper or lib of your own. I just simply use email lib class as per your reference
     if($bSendStatus){
       echo json_encode(array('success'=>1, message=>'OK email sent'));
     }
 }
 echo json_encode(array('success'=>0, message=>'Your message on failure'));

}
function send_email($user_data){
    $this->load->library('email'); //may have it in function __contruct at beginning of controller
      $email_from = $user_data['useremail'];
      $username = $user_data['username'];
       $content_submitted = $user_data['content_submitted'];
      $this->email->from($email_from, );
      $this->email->to('[email protected]');
      $this->email->cc('[email protected]');
       $this->email->bcc('[email protected]');

       $this->email->subject('Email Test');
        $this->email->message($content_submitted);

       $this->email->send();
      return TRUE; // or you can further find out what this->email->send return  
}

  Just quick suggestion, and you can adapt to your use with some modification to suit

  Good luck
Reply


Messages In This Thread
Send email from a post - by Marcolino92 - 09-25-2017, 11:25 AM
RE: Send email from a post - by InsiteFX - 09-26-2017, 03:07 AM
RE: Send email from a post - by ciadvantage - 09-27-2017, 02:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB