I am trying to learn PHP.
I have been working on this script for a while and am getting no where. Can someone please tell me what is going on? Why isn’t it displaying the errors and sending the information to a email address.
// I replaced my email address with non existent email address for security reasons
// Send the information to this email address
$to = "email@isp.net";
// Getting the variables from the contact form
$title = $HTTP_POST_VARS['title']; // Title
$fullname = $HTTP_POST_VARS['fullname']; // Full Name
$position = $HTTP_POST_VARS['position']; // Position Title
$company = $HTTP_POST_VARS['company']; // Company Name
$address = $HTTP_POST_VARS['address']; // Address
$phone = $HTTP_POST_VARS['phone']; // Phone Number
$fax = $HTTP_POST_VARS['fax']; // Fax Number
$mobile = $HTTP_POST_VARS['mobile']; // Mobile Number
$email = $HTTP_POST_VARS['email']; // Email Number
$subject = $HTTP_POST_VARS['subject']; // Subject of the email
$body = $HTTP_POST_VARS['body']; // Message/body
// The headers for the email
$header = "From: $email";
// The message of the email
$message =
"Title: $title
Full Name: $fullname
Position Title: $position
Company Name: $company
Address: $address
Phone Number: $phone
Fax Number: $fax
Mobile Number: $mobile
Email Address: $email
Message: $body";
// Checking that the required fields are filled in
if (isset ($_POST['send'])) {
$problem = FALSE;
if (empty ($_POST['title']))
{
$problem = TRUE;
print "<centre><b>Please enter your title. </b></centre>";
print "<centre><a href='javascript:history.back(1);'>Back</a></centre><br />";
} else {
$_POST = ""; // Clearing the field
}
if (empty ($_POST[$fullname]))
{
$problem = TRUE;
print "<centre><b>Please enter your full name. </b></centre>";
print "<centre><a href='javascript:history.back(1);'>Back</a><br /></centre>";
} else {
$_POST = ""; // Clearing the field
}
if ($phone < 8)
{
$problem = TRUE;
print "<centre><b>Please enter your phone number. </b></centre>";
print "<centre><a href='javascript:history.back(1);'>Back</a><br /></centre>";
} else {
$_POST = ""; // Clearing the field
}
if (empty ($_POST[$email]))
{
print "<centre><b>Please enter your email address. </b></centre>";
print "<centre><a href='javascript:history.back(1);'>Back</a><br /></centre>";
} else {
$_POST = ""; // Clearing the field
}
if (empty ($_POST[$subject]))
{
$problem = TRUE;
print "<centre><b>Please enter a subject for this email. </b></centre>";
print "<centre><a href='javascript:history.back(1);'>Back</a><br /></centre>";
} else {
$_POST = ""; // Clearing the field
}
if (empty ($_POST[$body]))
{
$problem = TRUE;
print "<centre><b>Please enter a message for this email. </b></centre>";
print "<centre><a href='javascript:history.back(1);'>Back</a><br /></centre>";
} else {
$_POST = ""; // Clearing the field
}
// No fields are empty now sending the information to the email address ($to)
if ((!empty ($_POST['title'])) && (!empty ($_POST['fullname'])) && (!empty ($_POST['phone'])) && (!empty ($_POST['email']))
&& (!empty ($_POST['subject'])) && (!empty ($_POST['body']))
{
print '<p><b>Message has been sent!</b></p>';
mail($to, $subject, $message, $headers);
}
}