I am trying to insert the name, email, company, phone and country from the array into the email message, but all I get is an empty email. The subject, to and from all works, but I am not getting the message in the email. Can anyone tell me what I am doing wrong?
<? php
public function contact_mail() {
$data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
'country' => $this->input->post('country')
);
$success = $this->data->save_contact_info($data);
if ($success) {
$data = array('success_message' => 'Thank you. We\'ll be in touch.');
$this->load->view('ajax/json', array('json' => $data));
$this->load->library('email');
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from("noreply@example.com", "Example Notification Service");
$this->email->to(array('mha@example.com'));
$this->email->subject('Contact form');
$this->email->message($data);
$this->email->send();
}
else {
$this->load->view('ajax/error', array('error_msg' => 'Please fill out all fields.'));
}
}
?>
Change this line:
$this->load->view('ajax/json', array('json' => $data));
to this:
$view = $this->load->view('ajax/json', array('json' => $data));
Then instead of sending $data
through which is just an array
, you send through $view
which is the HTML that includes the array.
Also, you're using $data
to get all of the POST
variables, but then use data
later to set a flash message.
I'm not sure whether you mean to overwrite $data
or not, but it's always best to keep the variable names different for different things.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.