Hey all,
I have run into a problem, and I was hoping someone could advise: I am
creating a contact form. One of the inputs (Radio Button) asks the
user if they are either a "New Client" or an "Existing Client". Based
on their selection, I'd like to send the data to a different email:
newc...@yourdomain.com and
existin...@yourdomain.com
Some code:
----------------------------------------------------------------------------------------------------------------------------
CONTACT.HTML:
----------------------------------------------------------------------------------------------------------------------------
<form action="contact.php" method="post">
<p>Name: <input type="text" name="yourname" /><br />
E-mail: <input type="text" name="email" /><br />
Telephone: <input type="text" name="telephone" /><br />
Address: <input type="text" name="street" /><br />
City: <input type="text" name="city" /><br />
State: <select name="state">
<option value="blank"> </option>
<option value="AL">Alabama</option>
...
<option value="WY">Wyoming</option>
</select>
Zip: <input type="text" name="zip"></p>
<p>Are you a current client?
<input type="radio" name="client" value="Yes" /> Yes
<input type="radio" name="client" value="No" /> No</p>
<p><b>Your comments:</b><br />
<textarea name="inquiry" rows="10" cols="40"></textarea></p>
<p><input type="submit" value="Send it!"></p>
</form>
----------------------------------------------------------------------------------------------------------------------------
CONTACT.PHP
----------------------------------------------------------------------------------------------------------------------------
<?php
/* Set e-mail recipient */
if ( $_POST['client'] == 'yes' ){
$myemail = "
existin...@yourdomain.com";
} elseif ( $_POST['client'] == 'no' ) {
$myemail = "
newc...@yourdomain.com";
}
/* Gets all inpus */
$yourname = check_input($_POST['yourname'], "Enter your name");
$email = check_input($_POST['email']);
$telephone = check_input($_POST['telephone']);
$street = check_input($_POST['street']);
$city = check_input($_POST['city']);
$state = check_input($_POST['state']);
$zip = check_input($_POST['zip']);
$client = check_input($_POST['client']);
$inquiry = check_input($_POST['inquiry'], "Write your comments");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)){
show_error("E-mail address not valid");
}
/* Message emailed */
$message = "Hello!
Your contact form has been submitted by:
Name: $yourname
Email: $email
Telephone: $telephone
Address:
$street
$city, $state $zip
Current Client: $client
Message:
$inquiry
End of message
";
/* Send the message using mail() function */
mail($myemail, "Contact via GordonReevesLaw.com", $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
/* Strips message of crazy characters */
function check_input($data, $problem=''){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0){
show_error($problem);
}
return $data;
}
/* Show errors */
function show_error($myError){
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
----------------------------------------------------------------------------------------------------------------------------
So, in testing the form, I filled it out, once as a new client, and
once as an existing client. However, regardless of which radio button
I select, both form-entries are sent to the latter email.
Any ideas on why my if-statement isn't working? Can I not look to see
if the input matches a string on a radio button? I'm a little lost,
and most of the tutorials I've looked at online address sending forms
to multiple email addresses, not different addresses.
Thanks in advance,
Domanique