big-dog1965 Posted September 4, 2007 Share Posted September 4, 2007 Is it posible to have a email sent to differant people depending on a selection made from a drop down on a form. The drop down choices are Wichita, AMain, Hutchison, Enid, Action, Newton. Only one can be selected on the form. So for instance if Wichita was selected an email would be sent to wichitaatwichita.com If AMain was selected an email would go to AMainatamain.com and so on. The form, PHP, and database was created from a formgenerator information is sent to database a thank you type page is created and an email is sent with form information. Right know the thing just emails to a set email in code around line 68. I dont really have a clue to this stuff so please show me. Here is the PHP <?php include("global.inc.php"); $errors=0; $error="The following errors occured while processing your form input.<ul>"; pt_register('POST','FirstName'); pt_register('POST','LastName'); pt_register('POST','Address'); pt_register('POST','City'); pt_register('POST','State'); pt_register('POST','ZipCode'); pt_register('POST','HomePhone'); pt_register('POST','CellPhone'); pt_register('POST','EMail'); pt_register('POST','MembershipNo'); pt_register('POST','RoarNo'); pt_register('POST','FirstClass'); pt_register('POST','TransmitterFrequency'); pt_register('POST','TransponderNo'); pt_register('POST','TrackTransponder'); pt_register('POST','SecondClass'); pt_register('POST','TransmitterFrequency2'); pt_register('POST','TransponderNo2'); pt_register('POST','TrackTransponder2'); pt_register('POST','AbilitySkillLevel'); pt_register('POST','RaceDate'); pt_register('POST','Track'); pt_register('POST','IPAddress'); pt_register('POST','DatePosted'); if($FirstName=="" || $LastName=="" || $Address=="" || $City=="" || $State=="" || $ZipCode=="" || $EMail=="" || $FirstClass=="" || $TransmitterFrequency=="" || $AbilitySkillLevel=="" || $RaceDate=="" || $Track=="" ){ $errors=1; $error.="<li>You did not enter one or more of the required fields. Please go back and try again."; } if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMail)){ $error.="<li>Invalid email address entered"; $errors=1; } $IPAddress = $HTTP_SERVER_VARS["REMOTE_ADDR"]; $DatePosted = date("Y-m-d h:i"); if($errors==1) echo $error; else{ $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); $message="First Name: ".$FirstName." Last Name: ".$LastName." Address: ".$Address." City: ".$City." State: ".$State." Zip Code: ".$ZipCode." Home Phone: ".$HomePhone." Cell Phone: ".$CellPhone." E Mail: ".$EMail." Membership No: ".$MembershipNo." Roar No: ".$RoarNo." First Class: ".$FirstClass." Transmitter Frequency: ".$TransmitterFrequency." Transponder No: ".$TransponderNo." Track Transponder: ".$TrackTransponder." Second Class: ".$SecondClass." Transmitter Frequency2: ".$TransmitterFrequency2." Transponder No2: ".$TransponderNo2." Track Transponder2: ".$TrackTransponder2." Ability Skill Level: ".$AbilitySkillLevel." Race Date: ".$RaceDate." Track: ".$Track." IP Address: ".$IPAddress." Date Posted: ".$DatePosted." "; $message = stripslashes($message); mail("wichita@wichita.com","".$FirstName." ".$RaceDate." Race Registration", $message,"From: $EMail"); $link = mysql_connect("localhost","logmein","withthispw"); mysql_select_db("form_21D",$link); $query="insert into Registration (First_Name,Last_Name,Address,City,State,Zip_Code,Home_Phone,Cell_Phone,E_Mail,Membership_No,Roar_No,First_Class,Transmitter_Frequency,Transponder_No,Track_Transponder,Second_Class,Transmitter_Frequency2,Transponder_No2,Track_Transponder2,Ability_Skill_Level,Race_Date,Track,IP_Address,Date_Posted) values ('".$FirstName."','".$LastName."','".$Address."','".$City."','".$State."','".$ZipCode."','".$HomePhone."','".$CellPhone."','".$EMail."','".$MembershipNo."','".$RoarNo."','".$FirstClass."','".$TransmitterFrequency."','".$TransponderNo."','".$TrackTransponder."','".$SecondClass."','".$TransmitterFrequency2."','".$TransponderNo2."','".$TrackTransponder2."','".$AbilitySkillLevel."','".$RaceDate."','".$Track."','".$IPAddress."','".$DatePosted."')"; mysql_query($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67951-form-email-notification-depends-on-drop-down/ Share on other sites More sharing options...
php_tom Posted September 4, 2007 Share Posted September 4, 2007 I don't want to write the code for you, but here's an example. <?php if($_GET['func']=='mail') { // Process the input $to = $_POST['to']; $from = "From: ".$_POST['from']."\r\n"; $subject = "Subject goes here"; $message = "Email message goes here"; if(mail($to, $subject, $message, $from) echo "Message successfully sent!"; else echo "Message could not be sent."; } else { // Print the form ?> <form action='ThisPage.php?func=mail' method='post'> Your Email: <input type='text' name='from' /> Send to: <select name='to'> <option value='person1@domain.com'>Person 1</option> <option value='person2@domain.com'>Person 2</option> <option value='person3@domain.com'>Person 3</option> </select> <textarea name='message'></textarea> <input type='submit' value='Send' /> </form> <?php } ?> Of course this code isn't highly secure... but it should do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/67951-form-email-notification-depends-on-drop-down/#findComment-341585 Share on other sites More sharing options...
big-dog1965 Posted September 5, 2007 Author Share Posted September 5, 2007 I dont want to rewrite the code just mod what I got. Here is some of the form that I think will be associated with the above PHP if that helps. <form enctype='multipart/form-data' action='Regist.php' method='post'> <table border=1> </table> <div align="center"> <table width='52%' border=1 cellspacing="1"> <tr><td align="left"> <b> Track*</b></td> <td align="left"> <select name='Track'"> <option value='Wichita' selected>Wichita <option value="Hutchison">Hutchison</option> <option value='A Main'>A Main <option value="Pea Body">Pea Body</option> <option value="Newton">Newton</option> <option value="Action RC">Action RC</option> <option value="Enid">Enid</option> </select></td> </tr> </table> </div> </td></tr></table> <input type='submit' value='Submit Form'"> <input type=reset value='Clear Form'"></p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/67951-form-email-notification-depends-on-drop-down/#findComment-341694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.