0

Could anyone tell me if there is something wrong with the code or a better way to modify it? for some reason when i hit submit on my contact form it displays the "error.html" page but i still get an email sent to my account.

$EmailTo = "[email protected]";
$Subject = "Contact Submission";

$Name = Trim(stripslashes($_POST['name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Budget = Trim(stripslashes($_POST['budget'])); 
$Message = Trim(stripslashes($_POST['message']));

// prepare email body text
$Body = 'Contact Submission'."\n";
$Body .= 'Name:        '   .$Name."\n";
$Body .= 'Email:       '   .$Email."\n";
$Body .= 'Budget:      '   .$Budget."\n";
$Body .= 'Message:     '   .$Message."\n";


// send email 
$success_email = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page
// CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE
    if ($success){
     header ('location:thankyou.html');
    } 
    else{
    header ('location:error.html');
    }
1
  • 1
    it's good form to put an exit; under your location headers - to ensure the page won't be parsed in an unlikely event Commented Aug 14, 2009 at 3:03

3 Answers 3

8

Change

if ($success){

to

if ($success_email){

$success doesn't exist...

Sign up to request clarification or add additional context in comments.

Comments

0
 $EmailTo = "[email protected]";
$Subject = "Contact Submission";

$Name = Trim(stripslashes($_POST['name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Budget = Trim(stripslashes($_POST['budget'])); 
$Message = Trim(stripslashes($_POST['message']));

// prepare email body text
$Body = 'Contact Submission'."\n";
$Body .= 'Name:            '   .$Name."\n";
$Body .= 'Email:           '   .$Email."\n";
$Body .= 'Budget:          '   .$Budget."\n";
$Body .= 'Message:     '   .$Message."\n";


// send email 
$success_email = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page
// CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE
    if ($success_email){
     header ('location:thankyou.html');
    } 
    else{
    header ('location:error.html');
    }

Comments

0
//Checking for empty for redirecting error page
if(empty($Name) || empty($Email)||empty($Budget)) 
{
    header('Location:error.html');
    exit;
}

//Send the email! if the fileds are not empty
mail($EmailTo, $Subject,$Body,"From: <$Email>");

//One the email is sent, Redirect to thankyou page.
header('Location: thankyou.html');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.