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

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.


PHP Code:
public function view($id null) {
       $data['itemView'] = $this->items_model->getItem($id);
       if (empty($data['itemView'])) {

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

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 CodeIgniter Community 2009.  ( Skype: insitfx )

(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
//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  
//your action code here for what being as data return
// i.e
  console.log('maybe some message on the form ' + data.message);

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
     $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
       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');

      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

Theme © iAndrew 2016 - Forum software by © MyBB