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

(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) {
$this->load->view('frontend/header');
        $this->load->view('frontend/contact_us');
        $this->load->view('frontend/footer');
        }else{
        $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');
       
        }
redirect($this->uri->uri_string());
        }
}

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') ?>
            </div>
          <?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">
<br>
<label for='email'>Email*</label><input type='text' id="email" name="email">
<br>
<label for='message'>Message*</label><textarea id='message' name='message'></textarea>
<br>
<input type='submit' value='Send' name='submit'>
  </form>
       </div>


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.
Reply
#2

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.
Reply
#3

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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB