[eluser]doubleplusgood[/eluser]
Hi there,
I have a website hosted with MediaTemple that has a CI contact form. I've noticed that when I set the 'to' address as one of the domain email accounts, the enquiry from the contact form is never received.
I know that the form definitely works, because when i change the 'to' address to a non-domain related email address, such as a gmail account - the enquiry from the contact form is received.
Wondered if anyone else had experienced this problem?
My Contact controller is here (Note: I'm using the constants.php file to set SITE_EMAIL and SITE_TITLE);
Code:
function send()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('company', 'Company', 'trim|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
$this->form_validation->set_rules('telephone', 'Telephone', 'trim|xss_clean');
$this->form_validation->set_rules('enquiry', 'Enquiry', 'trim|required');
if($this->form_validation->run() == FALSE)
{
$view_data['title'] = "Contact";
$view_data['body'] = "contact";
$view_data['view_file'] = 'contact/index';
$this->load->view('layouts/layout', $view_data);
}
else
{
// validation has passed. Now send the email
$title = $this->input->post('title');
$firstname = $this->input->post('first_name');
$lastname = $this->input->post('last_name');
$company = $this->input->post('company');
$email = $this->input->post('email');
$telephone = $this->input->post('telephone');
$enquiry = $this->input->post('enquiry');
$data['title']=$title;
$data['firstname']=$firstname;
$data['lastname']=$lastname;
$data['company']=$company;
$data['email']=$email;
$data['telephone']=$telephone;
$data['enquiry']=$enquiry;
$message=$this->load->view('messaging/contact',$data,true);
$this->load->library('email');
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->set_newline("\r\n");
$this->email->initialize($config);
$this->email->from($email);
$this->email->to(SITE_EMAIL, SITE_TITLE);
$this->email->subject('Enquiry');
$this->email->message($message);
if($this->email->send())
{
$this->session->set_flashdata('message', "Thank you for contacting us. We will reply to your enquiry within 24 hours.");
redirect('contact/index');
}
else
{
$this->session->set_flashdata('message', "Something went wrong. Please try again.");
redirect('contact/index');
}
}
}