This topic was solved at another forum with a minor code adjustment to check the fields before sending. Here is the adjusted code, look above the "$to = " line and also at the very end of the code at the bottom to see the changes:
<?php
$name = trim(htmlentities($_POST['name'],ENT_QUOTES,'utf-8'));
$company = trim(htmlentities($_POST['company'],ENT_QUOTES,'utf-8'));
$email = trim(htmlentities($_POST['email'],ENT_QUOTES,'utf-8'));
$phone = trim(htmlentities($_POST['phone'],ENT_QUOTES,'utf-8'));
$interest = trim(htmlentities($_POST['interest'],ENT_QUOTES,'utf-8'));
$comments = trim(htmlentities($_POST['comments'],ENT_QUOTES,'utf-8'));
if($name != '' && $company != '' && $email != '' && $phone != ''){
$to = "me@mysite.com";
$subject = "Visitor Contact";
$message = "Name: ".$name;
$message.="\n\nCompany: ".$company;
$message.="\n\nEmail: ".$email;
$message.="\n\nPhone: ".$phone;
$message.="\n\nInterest: ".$interest;
$message .= "\n\nMessage: ".$comments;
$headers = "From: $email";
$headers .="\nReply-To: $email";
$success = mail($to, $subject, $message, $headers);
if ($success) {
print ("<b>Thank you $name. You'll be hearing from us soon.</b>");
} else {
print ("<b>I'm sorry, there was a technical glitch, please send your email to [email]me@gmysite.com[/email] directly.</b>");
}
}
else
{
echo "Please fill the required fields, thankyou";
}
?>
and here is another solution that may be better or worse, however, I have not tested this one yet:
<?php
$name = trim(htmlentities($_POST['name'],ENT_QUOTES,'utf-8'));
$company = trim(htmlentities($_POST['company'],ENT_QUOTES,'utf-8'));
$email = trim(htmlentities($_POST['email'],ENT_QUOTES,'utf-8'));
$phone = trim(htmlentities($_POST['phone'],ENT_QUOTES,'utf-8'));
$interest = trim(htmlentities($_POST['interest'],ENT_QUOTES,'utf-8'));
$comments = trim(htmlentities($_POST['comments'],ENT_QUOTES,'utf-8'));
if (strlen($name) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back fill out the required fields</font></p>");
}
if (strlen($company) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back fill out the required fields</font></p>");
}
if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back fill out the required fields</font></p>");
}
if (strlen($phone) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back fill out the required fields</font></p>");
}
$to = "me@mysite.com";
$subject = "Visitor Contact";
$message = "Name: ".$name;
$message.="\n\nCompany: ".$company;
$message.="\n\nEmail: ".$email;
$message.="\n\nPhone: ".$phone;
$message.="\n\nInterest: ".$interest;
$message .= "\n\nMessage: ".$comments;
$headers = "From: $email";
$headers .="\nReply-To: $email";
$success = mail($to, $subject, $message, $headers);
if ($success) {
print ("<b>Thank you $name. You'll be hearing from us soon.</b>");
} else {
print ("<b>I'm sorry, there was a technical glitch, please send your email to me@gmysite.com directly.</b>");
}
?>