• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send email from a post

#1
Hi guys, I would like that in the specific post posted by a user, the visitor interested in the ad could contact him by email. Just that I want everything to be on the same page, I do not want a page to send mail, but in the same post.

https://www.codeigniter.com/user_guide/l...il-library

PHP Code:
public function view($id null) {
 
       $data['itemView'] = $this->items_model->getItem($id);
 
       if (empty($data['itemView'])) {
 
           show_404();
 
       }
 
       $this->load->view('themes/header'$data);
 
       $this->load->view('items/view'$data);
 
       $this->load->view('themes/footer');
 
   

This is the View function in the controller, what should I do?
Reply

#2
Then you would need to add the user etc to a database and send it later.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#3
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.