Code: Select all
<?php
// If the form has been posted, analyse it:
if ($_POST) { // CURLY BRACKET (Open): After Clicking Submit
foreach ($_POST as $field => $value) {
$value = trim($value);
}
// Creating Variables
$to="my@mail.com";
$inquiry=$_POST['inquiry'];
$dname=$_POST['dname'];
$name=$_POST['name'];
$surname=$_POST['surname'];
$email=$_POST['email'];
$reasonforservice=stripslashes($_POST['reasonforservice']);
$getcopy=$_POST['getcopy'];
$security_code=$_POST['security_code'];
$headers=$_POST['email'];
$header1= Thank you for your email, a copy of your Search Promotion service email is displayed below:" . "\r\n" .
" " . "\r\n" .
"Copy of your Inquiry: " . $_POST['inquiry'] . "\r\n" .
"DName: " . $_POST['dname'] . "\r\n" .
"Name: " . $_POST['name'] . "\r\n" .
"Surname: " . $_POST['surname'] . "\r\n" .
"E-mail: " . $_POST['email'] . "\r\n" .
" ". "\r\n" .
"Message: " . $_POST['reasonforservice'] . "\r\n" .
" ". "\r\n" .
" ". "\r\n" .
" ". "\r\n";
$header2="From: " . $email . "\r\n" .
"Customer Inquiry: " . $_POST['inquiry'] . "\r\n" .
"DName: " . $_POST['dname'] . "\r\n" .
"Name: " . $_POST['name'] . "\r\n" .
"Surname: " . $_POST['surname'] . "\r\n" .
"E-mail: " . $_POST['email'];
// Create empty ERROR variables
$error = ""; // for fields left BLANK
$errorflag = ""; // for fields with INVALID data entered
// Check for field/fields that is/are left BLANK
if (($dname == "") || ($name == "") || ($surname == "") || ($email == "") || ($reasonforservice == "")) { // CURLY BRACKET (Open): For Validating if fields are left blank
$error = "<span class='colorTextBlue'>Please fill in all fields!</span>";
} // CURLY BRACKET (Close): For Validating if fields are left blank
else { // CURLY BRACKET (Open): Form Validation
// Validate First Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
if (ctype_alpha($dname) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid DName <span class='italic'>(Alphabets only)</span></span>";
$errorflag= "dname";
}
// Validate Last Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (ctype_alpha($name) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Name <span class='italic'>(Alphabets only)</span></span>";
$errorflag="name";
}
// Validate Last Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (ctype_alpha($surname) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Surname <span class='italic'>(Alphabets only)</span></span>";
$errorflag="surname";
}
// Validate E-mail (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if ((strpos($email, "@") == FALSE) || (strpos($email, ".") == FALSE) || (strpos($email, " ") != FALSE)) {
$error = "<span class='colorTextBlue'>Please enter a valid E-mail</span>";
$errorflag="email";
}
} // CURLY BRACKET (Close): Form Validation
// Confirmation Message seen AFTER filling the form and pressing "Submit" button (whether there's an error or not)
// If there's an error along with displaying the list of flagged error/errors
if ($error != "") { // CURLY BRACKET (Open): For Error
echo "<br/> <b><span class='colorTextRed'>Error Occured: </b>" . $error."</span>" ;
} // CURLY BRACKET (Close): For Error
// If there's NO error at all, along with displaying the filled fields
else if (mail($to, $inquiry, $reasonforservice, $header2))
{
echo "<p><span class='colorTextBlue'>E-mail sent successfully</span></p> <br/><br/>";
echo "<p>Thanks for your comment and time. We will be in touch with you shortly, if required. Following are the details you filled in.<br/><br/></p>";
echo "<b>Nature of Inquiry:</b> ". $inquiry . "<br/>";
echo "<b>DName:</b> ". $dname . "<br/>";
echo "<b>Name:</b> ". $name . "<br/>";
echo "<b>Surname:</b> ". $surname . "<br/>";
echo "<b>E-mail:</b> ". $email . "<br/>";
echo "<b>Message:</b> ". $reasonforservice . "<br/></p>";
echo "<br/><br/><p>Please now pay for your </p><br/>";
echo "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">";
// HIDDEN
echo "</form>";
}
else {
$error = "<span class='colorTextRed'> E-mail NOT sent</span>";
}
if ($getcopy=="1") {
mail($email, $inquiry, $header1, "From:\"$bbtitle My Company\" <$to>");
}
} // CURLY BRACKET (Close): After Clicking Submit
// Displays the Empty variables i.e. when the Contact Form appears completely blank for the VERY FIRST time with all blank fields
else {
$inquiry = "";
$dname = "";
$name = "";
$surname = "";
$email = "";
$reasonforservice = "";
$errorflag = "";
}
?>
<?php
} else {
// Insert your code for showing an error message here
echo '<p>Sorry, you have provided an invalid security code</p>';
}
}
?>
Can someone please help me with this particular problem. I'd be grateful as its doing my head in.