I have the following script that recieves data from a webform
When the email is BLANK it DOES show the correct message
If the eMail is INVALID it DOES show the correct message
HOWEVER - it still sends the message to the appropriate department, though without a sender's email address.
What did I miss to say - ONLY if the validation is true to move on the the rest of the code and send the message????
I don't want the message sent at all if the email isn't validated.
It's probably another IF statement isn't it?
<?php
/*
###################################################################################
CONTACT_US_PROC.PHP
###################################################################################
This will receive data from webform will check the validity of the sender's
email address, if invalid present the appropriate error message.
If the email address is validated and completed, the message will be checked for
the department and sent to the appropriate recipient.
A confirmation email will then be sent to the sender of the message and a
confirmation message posted to screen.
###################################################################################
*/
extract($_GET); // extract the variables from the submitted form data
extract($_POST);
// CHECK THE VALIDITY OF EMAIL ADDRESS
// If eMail is not a valid address
if ($sender){
$sender=trim($sender); // Remove white space from email field
//Check if email DOES NOT contain a valid form
if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$sender)){
?>
<!-- DISPLAY INVALID EMAIL ERROR MESSAGE WITH BACK BUTTON -->
<html>
<font face=Arial size=6>
<b>ERROR:</b> <BR>
<font face=Arial Size=3>
You did not enter an appropriate email address.<BR>
Please correct this information.<BR>
<input type=button onClick="javascript:history.back(1);" value="Go Back"><BR>
</font>
</font>
</html>
<?php
}
//Check to see if email is blank
}elseif(!$sender) {
?>
<!--DISPLAY NO EMAIL ADDRESS MESSAGE -->
<html>
<FONT face=Arial Size=6>
<b>ERROR:</b> <BR>
<font face=Arial Size=3>
You did not enter an email address.<BR>
Please correct this information.<BR>
<input type=button onClick="javascript:history.back(1);" value="Go Back"><BR>
</font>
</font>
</html>
<?php
}
// Check which department was selected.
switch ($dept) {
case 1:
$recipient = "user1@mydomain.com"; // First Choice's eMail add.
break;
case 2:
$recipient = "user2@mydomain.com"; // 2nd Choice's email
break;
case 3:
$recipient = "user3@mydomain.com"; // 3rd Choice's email
break;
// Add additional cases here
}
// Post confirmation to screen
echo "Your message has been forwarded to the proper department.<BR>
Thank you for your input.";
// Send mail to proper department
mail($recipient,"Website Contact",$message,"FROM:$sender");
// Send confirmation email to visitor
mail($sender,"Webmaster","The following message was sent to
mydomain.com \r $message \n","FROM:admin@mydomain.com");
?>