Welcome Guest, Not a member yet? Register   Sign In
Contact Form Failure

(This post was last modified: 08-19-2015, 11:32 PM by jjalvi.)

Hi there, I have a codeignitor based web portal accessible via www.webuyback.com.au I have a problem with my Contact Us Page form. Even after filling in all the details and hitting submit, I am not receiving any emails. The contact us page is located at http://www.webuyback.com.au/front_controller/contact_us

The code from front_controller.php that goes with the form is :

public function contact_us()
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
               $this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[3]|max_length[100]|valid_email');
               $this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) {
        $name = $this->input->post('name');
        $from = "[email protected]";
        $subject = "Contact Inquiry by ".$name;
        //$message = $this->input->post('message');
        $message = "From email : ".$this->input->post('email')."<br>".$this->input->post('message');
        $headers = "From: " . $name . "<" . $from . ">" . "\r\n";
        $headers .= 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
        $to = "[email protected]";
        if(mail($to, $subject, $message, $headers)){
        $this->session->set_flashdata('successful_msg_contact','Your message has been sent successfully');

Also the code from contact_us.php is :

<?php if($this->session->flashdata('successful_msg_contact')): ?>
            <div class="alert alert-success">
            <?php echo $this->session->flashdata('successful_msg_contact') ?>
          <?php endif; ?>
  <form action='<?php echo base_url() ?>front_controller/contact_us' method='POST'>
<label for='name'>Name*</label><input type='text' id="name" name="name">
<label for='email'>Email*</label><input type='text' id="email" name="email">
<label for='message'>Message*</label><textarea id='message' name='message'></textarea>
<input type='submit' value='Send' name='submit'>

Any help to sort it out will be much appreciated. I cannot get hold of my developer and this error is just causing me trouble.

Thanks in advance.

Since mail() appears to be returning true, you have to check the server's logs to determine why it failed.

I would recommend using CI's email library instead of using mail() directly, in case you need to use some other method to send email, but there's not much point in changing code before you know what the problem really is.

Thanks mwhitney,

The fix was pretty simple. As you suggested, i went on to my web cPanel and checked out the mx settings. Just changed it from Automatic (recommended) to External mail server as we have out own mail server setup and that fixed the issue.

Thanks for pointing it out and having a look at the code! Cheers!

Theme © iAndrew 2016 - Forum software by © MyBB