05-26-2008, 02:38 AM
|
#1 (permalink)
|
|
The Visitor
Join Date: May 2008
Posts: 3
Thanks: 0
|
PHP Contact Form - 2 Questions
I have a few questions about this contact form I'm making in PHP:
1. How can I use the "header" method when I have HTML tags?
2. I want my form to only send an email if all the forms are filled out. I've heard about using "elseif" but I don't know how to use it with 3 variables.
Here's the code (there is CAPTCHA code, but I'm not showing it for security purposes)
PHP Code:
<?php
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$comments = $_POST['comments'];
// Build the email
$to = 'mason@masonsklut.com';
$subject = "Comment";
$message = "Name: $name" . "\n" . "E-mail: $email" . "\n" . "URL: $url" . "\n" . "Comment: $comments";
$headers = "From: $name" . "\r\n" .
"Reply-To: $email";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
header ('Location: http://masonsklut.com/test/success.html');
// Mail header removal
function remove_headers($string) {
$headers = array(
"/to\:/i",
"/from\:/i",
"/bcc\:/i",
"/cc\:/i",
"/Content\-Transfer\-Encoding\:/i",
"/Content\-Type\:/i",
"/Mime\-Version\:/i"
);
$string = preg_replace($headers, '', $string);
return strip_tags($string);
}
// Pick up the cleaned form data
$name = remove_headers($_POST['name']);
$email = remove_headers($_POST['email']);
$url = remove_headers($_POST['url']);
$comments = remove_headers($_POST['comments']);
// Field verification
if($name == "") {
echo "<span class=\"text\"><p>Please enter required fields!</p></span>";
if($subject == "")
echo "<span class=\"text\"><p>Please enter required fields!</p></span>";
if($email =="")
echo "<span class=\"text\"><p>Please enter required fields!</p></span>";
mail();
}
?>
|
|
|
|