1

im using this contact form below. When I was running it on my local machine it was working. But on my server if the form fails it does the right thing and goes to fail.php but when all the fields are filled it goes to send_contact2.php after clicking send instead of success.php

This is the send_contact2.php

if (empty($_POST['name'])
    || empty($_POST['number'])
    || empty($_POST['email'])
    || empty($_POST['messagearea'])
){
    header('Location: fail.php');
}

else {

    $name = $_POST['name'];
    $number = $_POST['number'];
    $email = $_POST['email'];
    $messagearea = $_POST['messagearea'];

    $to = 'example@gmail.com';
    $subject = "Website Message: Contact form";
    $message = '$messagearea';
    $headers = "From: WebsiteMessage";

    mail($to, $subject, $message, $headers);

    header("Location: success.php");

}
?>

This is my form

<form name="form1" method="post" action="send_contact2.php">
    <input name="name" type="text" placeholder="Your Name"/> <br/>
    <input name="email" type="email" placeholder="Your Email"/> <br/>
    <input name="number" type="tel" placeholder="Your Number"/> <br />
    <textarea name="messagearea" cols="" rows="" id="messagearea" placeholder="Your Message"/></textarea> <br/>

    <input name="sumbit" type="submit" value="SEND" id="button2" />
</form>

I have this setting in my cPanel

enter image description here

Any help would be greatly appreciated

BritishSam
  • 1,070
  • 8
  • 24

3 Answers3

0

if the page stay on send_contact2.php it is because, header("Location: success.php") do not redirect. read this post, it could help. Php header location redirect not working

Community
  • 1
  • 1
letrounet
  • 91
  • 1
  • 3
0

In my opinion PHP must be outputing some text (char, error or warning?) or you have used a char before <?php in your send_contact2.php file. That's why header is not working. Remember that header() must be called before any actual output is sent.

  • was a php setting on my hosting with the mail server, i'll put it as the answer when i'm allowed to. cheers tho – BritishSam Sep 01 '16 at 08:10
0

OP here, managed to sort it in the end

Was a mail server issue, so if anyone in the future gets this problem check your php settings on your hosting and make sure it allows mail() and make sure you set up an email address where you're sending the email to on your server.

thanks to everyone that helped me debug

BritishSam
  • 1,070
  • 8
  • 24