Please help! New to php: header/thank you page issue

Hi, I’m new to using php and I’m attempting to create a form using the php function. I got the form to work and it sends me the emails. However I want it to redirect the individual to a thank you page, I’ve created. I cannot get it to work. Whenever I click submit, it just remains on the page. Although I do receive the email with the information. Please help!

Thanks

[php]<?php
function isValidEmail($email){
return eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email);
}

$email = $_POST[‘email’];
$name = $_POST[‘name’];
$to = ‘[email protected]’; //Please enter your email!

$subject = “Contact form”; //Please enter your subject!
$message = $_POST[‘msg’];
$headers = ‘From: ‘.$name.’<’.$email.’>’;

if (($_POST[‘email’] == ‘’) || ($_POST[‘name’] == ‘’) || ($_POST[‘msg’] == ‘’)){
echo “false”;
return false;
} else {
if(isValidEmail($email)==true){
mail($to, $subject, $message, $headers);
echo “true”;
header(‘Location: thankyou.html’);
} else {
echo “false”;
}
}

?>[/php]

Here is my html for the contact form

                  <div class="form">
                    <form id="form" method="post" action="contact.php">
                      <label>Name:</label>
                      <input type="text" id="contact-name" name="name" class="input" value="" autocomplete="off"/>                  
                      <label>Email:</label>
                      <input type="text" id="contact-email" name="email" class="input" value="" autocomplete="off"/>
                      <label>Message:</label>
                      <textarea id="contact-msg" class="input" ></textarea>
                      <label><input type="submit" class="submit" value="Submit" name="submit"></label>                       
                    </form>
                  </div>               

Make sure that you have error_reporting = On and display_errors = On

You should be getting an error from your header() function that says “headers already sent” due to this code:

[php]echo “true”;[/php]

You cannot have any output before a header() call.

Sponsor our Newsletter | Privacy Policy | Terms of Service