I have a mailform that I use. In a new usage I have added 2 checkboxes. I would like to be able to send mail to differing addresses based on the check boxes.
EX: if “box1 checked mail to xx, if box 2 checked mail to xx, else mail to both. The code That I use to mail is:
<?
/************************
* Variables you can change
*************************/
$mailto = "";
$cc = "";
$bcc = "";
$subject = "contact";
$vname = "Enquiry";
/************************
* do not modify anything below unless you know PHP/HTML/XHTML
*************************/
/* my trial adjustment for check boxes
*/
$email = $_POST['email'];
function validateEmail($email)
{
if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email))
return true;
else
return false;
}
if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['message']) < 1 ) || validateEmail($email) == FALSE){
$emailerror .= '';
if(strlen($_POST['name']) < 1 ){
$emailerror .= '<li>Enter name</li>';
}
if(strlen($email) < 1 ){
$emailerror .= '<li>Enter email</li>';
}
if(validateEmail($email) == FALSE) {
$emailerror .= '<li>Enter valid email</li>';
}
if(strlen($_POST['message']) < 1 ){
$emailerror .= '<li>Enter message</li>';
}
} else {
$emailerror .= "Your email has been sent successfully";
// NOW SEND THE ENQUIRY
$timestamp = date("F j, Y, g:ia");
$messageproper ="\n\n" .
"Name: " .
ucwords($_POST['name']) .
"\n" .
"Email: " .
ucwords($email) .
"\n" .
"Telephone Contact: " .
ucwords($_POST['tel']) .
"\n" .
"Company: " .
ucwords($_POST['company']) .
"\n" .
"Comments: " .
$_POST['message'] .
"\n" .
"\n\n" ;
$messageproper = trim(stripslashes($messageproper));
mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() );
}
?>
<div id='emailerror'>
<ul>
<? echo $emailerror; ?>
</ul>
</div>
The check box code:
<label>MailPersonA</label>
<input type="checkbox" name="A" value="checkbox" id="A" />
<label>MailPersonB</label>
<input type="checkbox" name="B" value="checkbox" id="B" />
Any help will be appreciated.
You probably want to:
So your HTML would be
Now
$_POST['toaddress']will contain the destination email address.