Hi everyone,
I have a PHP mail script that validates name, email address, and phone number before sending the mail. This then means that the Name, Email address, and Phone fields are Required Fields.
I want to have it so that the Name and EITHER Email or Phone are required. Such that if a name and phone are inputted, it sends the mail, or if a name and an email are inputted, it also sends the email.
The way the script works right now is it has several IF statements that check for (1) name, (2) email and (3) phone. Here's an example of an if statement of the code:
if ( ($email == "") ) {
$errors .= $emailError; // no email address entered
$email_error = true;
}
if ( !(preg_match($match,$email)) ) {
$errors .= $invalidEmailError; // checks validity of email
$email_error = true;
}
And here's how it sends the mail:
if ( !($errors) ) {
mail ($to, $subject, $message, $headers);
echo "<p id='correct'>";
echo "?????? ????? ??????!";
echo "</p>";
} else {
if (($email_error == true)) {
$errors != $phoneError;
/*echo "<p id='errors'>";
echo $errors;
echo "</p>";*/
}
if (($phone_error == true)) {
$errors != $emailError;
$errors != $invalidEmailError;
/*echo "<p id='errors'>";
echo $errors;
echo "</p>";*/
}
echo "<p id='errors'>";
echo $errors;
echo "</p>";
}
This doesn't work though. Basically this is what I want to do: If no email address was entered or if it was entered incorrectly, set a variable called $email_error to be true. Then check for that variable, and if it's true, then remove the $phoneError part of the $errors variable.
Man I hope I'm making some sense here. Does anyone know why this doesn't work? It reports all errors if all fields are left empty :(
Thanks!
Amit