...

View Full Version : Help with contact form



lesh
01-15-2012, 08:57 AM
I am working on getting a contact form up and running for a website and have taken an example of someone else's. Only problem is I don't know anything about php so getting the form to work is proving difficult.

I have highlighted the lines I am unsure of with orange.
I don't know what I am supposed to put instead of junk@junk.om
Also, I am unsure how to change the URL to my contactthanks.html page. Everything I have tried will not work.


<?php

// CHANGE THE VARIABLES BELOW

$EmailFrom = "junk@junk.com";
$EmailTo = "aharper2000@hotmail.com";
$Subject = "Contact Form Submission";

$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

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

// redirect to success page
// CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>

Any help would be appreciated.
Here is a link to what I've got working so far: http://ah.mjtippet.com/contact.html

Fou-Lu
01-15-2012, 11:32 AM
For the first one, put whatever email you want it to arrive from.
For the second, use a header instead of a meta:


if ($success)
{
header('Location: http://yoursite.com/yourthankspage.html');
exit();
}
else
{
header('Location: http://yoursite.com/yourerrorpage.html');
exit();
}

lesh
01-15-2012, 09:03 PM
Thanks for your help. Are you able to tell me why you've changed it from print to header?

_Aerospace_Eng_
01-15-2012, 09:49 PM
It isn't about the print, it is about what was printed. Originally it would print out some HTML which was a Meta refresh. This would rely on the browser understanding it (most browsers do but it is obsolete). Using the header it ensures that it will always work no matter what browser.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum