[eluser]Unknown[/eluser]
Hello, I'm new to the forum. I've recently found CodeIgniter after thinking, "there's got to be a better way to do this." So far, I feel as if CodeIgniter ends that search.
I'm trying to send an email with post variables. It's also inserting the data into a database. My controller looks like this:
Code:
function contact_form(){
if($this->input->post('email')){
$this->load->model('MContacts', '', TRUE);
$this->MContacts->addContact();
$name = $this->input->post('name');
$email = $this->input->post('email');
$saddress = $this->input->post('saddress');
$phone = $this->input->post('phone');
$body = $this->input->post('message');
$mail_message = '
Name: ' .$name. '
Email: '.$email. '
Address: '.$saddress. '
Phone: '.$phone. '
Message: '.$body;
$this->email->from('VGH Form', 'VGH Form');
$this->email->to('[email protected]');
$this->email->subject('Submission from the Website');
$this->email->message($mail_message);
$this->email->send();
redirect('main/thanks', 'refresh');
} else {
redirect('main/contact', 'refresh');
}
$this->load->vars($data);
$this->load->view('template');
}
and my model looks like this:
Code:
function addContact() {
$now = date("Y-m-d H:i:s");
$data = array(
'name' => $this->input->xss_clean($this->input->post('name')),
'email' => $this->input->xss_clean($this->input->post('email')),
'saddress' => $this->input->xss_clean($this->input->post('saddress')),
'phone' => $this->input->xss_clean($this->input->post('phone')),
'message' => $this->input->xss_clean($this->input->post('message')),
'ipaddress' => $this->input->ip_address(),
'stamp' => $now);
$this->db->insert('contacts', $data);
}
This works properly, but I'm wondering if there's a better way to get the $data array with all the post variables into the message of the email, or if this is the best, most concise solution. For example, if I just replace $mail_message with $data, I get an error stating that $data is an undefined variable.
I'm hoping that I'm overlooking something simple and that a more experienced programmer can shed some light on this for me.
Thanks!
Nathan