whitedog Posted February 7, 2007 Share Posted February 7, 2007 Hi I am new to PHP and am trying to figure out how to write a variable based e-mail selection with a drop down menu. So if the user pulls down steves name in the drop down then the email will be sent to [email protected] otherwise if they pick sue it will go to [email protected] It also needs to be a required field. I think I am primarily getting hung up on how to declare the variable for the if statement. Below is my code <? if(isset($submit_button)) { $error_msg=''; if(trim($hname)=='' || strlen(trim($hname)) <1) { $error_msg.=" Please enter your name<br />"; } if(trim($email)=='') { $error_msg.=" Please enter an email<br />"; } else { if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email)) $error_msg.=" Please enter a valid email address<br />"; } if(trim($phone)=='' || strlen(trim($phone)) <10) { $error_msg.=" Please enter ten digit phone number<br />"; } if(trim($fname)=='' || strlen(trim($fname)) <1) { $error_msg.=" Please enter friend's name<br />"; } if(strlen($error_msg) == 0) { $myemail = "[email protected]"; $awesome = "[email protected]"; $todayis = date("l, F j, Y, g:i a") ; $subject = "Daycare Reservations" ; $message = " $todayis [EST]\n \n Location: $location \n Human's Name: $hname \n Email: $email \n Phone: $phone \n \n Friend's Name: $fname \n Breed: $breed \n Day Stay: $stay \n Comments: $comments \n"; $from = "From: $email\r\n"; if ($bishop = true) { mail($awesome, $subject, $message, $from); header("Location: thanks.php"); exit(); } if ($stjohn = true) { mail($myemail, $subject, $message, $from); header("Location: thanks.php"); exit(); } } } ?> Link to comment https://forums.phpfreaks.com/topic/37511-solved-variable-based-e-mail-address/ Share on other sites More sharing options...
whitedog Posted February 7, 2007 Author Share Posted February 7, 2007 to answer my own question this was my solution if ($location == "bishop") { mail($awesome, $subject, $message, $from); } if ($location == "stjohn") { mail($myemail, $subject, $message, $from); } header("Location: thanks.php"); Link to comment https://forums.phpfreaks.com/topic/37511-solved-variable-based-e-mail-address/#findComment-179443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.