chen2424 Posted November 15, 2009 Share Posted November 15, 2009 hi guys, ive got my form as below, dont mind the long options, just see that its now sending to 1 address. I want it such that if user choose from location dropdown, it will go to a diff email. eg, [email protected] for ASIA. [email protected] ofr america etcetc. ps:i stripped out alot of unwanted parts of the form so my post wont be so long. Any ideas very much appreciated! <?php //If the form is submitted if(isset($_POST['submit'])) { include_once("connects.php"); $lname=trim($_POST['lname']); $bustitle=trim($_POST['bustitle']); $company=trim($_POST['company']); $Location=$_POST['Location']; $vendor=trim($_POST['category']); $course=trim($_POST['subcategory']); $coLoc=$_POST['courseLoc']; $find=trim($_POST['find']); //Check to make sure that the name field is not empty if(trim($_POST['fname']) == '') { $hasError = true; } else { $fname = trim($_POST['fname']); } //Check to make sure that the subject field is not empty if(trim($_POST['phone']) == '') { $hasError = true; } else { $phone = trim($_POST['phone']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['comments']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['comments'])); } else { $comments = trim($_POST['comments']); } } $linkdate=date("Y-m-d", time()); //If there is no error, send the email if(!isset($hasError)) { $emailTo = '[email protected]'; //Put your own email address here $subject = "Registration"; $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $bodyuser = "Dear $fname,\n Thank you for your registration. We will get back to you as soon as possible \n\n\n \n"; $subjectuser = "Registration - Message Received"; $headersuser = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($email, $subjectuser, $bodyuser, $headersuser); $emailSent = true; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <link href="css/style_sheet.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> <script src="Scripts/jquery.validate.pack.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $("#formname").validate(); }); </script> <body > <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="formname" name="formname"> <table border="0" cellpadding="0" cellspacing="0" width="940" height="100%"> <tr> <td width="940" colspan="2" height="10" bgcolor="#ffffff"> </td> </tr> <tr> <td width="940" colspan="2" height="1"> </td> </tr> <!-- Header banner --> <!--hearder end--> <tr> <td width="940" height="18" colspan="2"> <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <!--content starts--> <td width="99%" valign="top" bgcolor="#FFFFFF" colspan=2> <table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="15"><img src="images/spacer.gif" alt="" width="15" height="1" border="0"></td> <td valign="top" align="left"> <!-- Content starts --> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="content"> <tr> <td> <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="content"><?php if(isset($hasError)) { //If errors are found ?> <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p><strong>Email Successfully Sent!</strong></p> <p>Thank you <strong><?php echo $name;?></strong> for your registration. Your email was successfully sent and we will be in touch with you soon.</p> <?php } ?> </td> <td width="5"><img src="images/spacer.gif" alt="" width="5" height="1" border="0"></td> </tr> <tr> <td align="left" valign="top" class="con_pad"> <div id="ctl00_ContentPlaceHolder2_ctl02_formReg2"> <table width="50%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="2%" class="con_pad1"> </td> <td width="32%" class="content">First name <br><br></td> <td width="2%" class="content">:<br><br></td> <td width="64%" class="content con_pad1"><table border="0" cellpadding="0" cellspacing="0"> <tr><td width="4" align="left"><img src="images/red_strip_frm.gif" alt="Mandatory field" align="absbottom"><br><br></td><td><input name="fname" type="text" maxlength="50" id="fname" class="required" style="width:200px;" /><br><br></td></tr></table></td></tr> <tr> <td class="con_pad1"> </td> <td class="content">Location<br><br></td> <td class="content"> </td> <td class="content con_pad1"><img src="images/red_strip_frm.gif" alt="Mandatory field" height="18" align="absbottom" /> <select name="courseLoc" id="courseLoc" class="required" > <option value="" selected="selected">--Select--</option> <option value="asia">asia</option> <option value="america">america</option> <option value="europe">europe</option> </select><br><br></td> </tr> <tr> <td width="2%" valign="top" class="con_pad1"> </td> <td width="32%" valign="top" class="content con_pad1">Comments </td> <td width="2%" valign="top" class="content con_pad1">:</td> <td width="64%" align="left" valign="top" class="con_pad1"><table border="0" cellpadding="0" cellspacing="0"> <tr><td width="4" align="left" valign="top"><img src="images/red_strip_frm_tarea.gif" alt="Mandatory field" align="absbottom"></td> <td><textarea name="comments" rows="3" cols="20" id="comments" class="required" style="width:200px;"></textarea></td></tr></table> <br /><br /></td> </tr> </table> </div></td> <td> </td> </tr> <tr><td colspan="4" align="center"><input type="submit" name="submit" value="Submit" id="submit" title="Submit" style="height:25px;width:70px;cursor:pointer;" /> </td></tr> </table> <!-- start more info --></td></tr> <!-- end more info --> </table> </td> </tr> </table> <!-- Content ends here --> </td> </tr> </table> </td> </tr> </table> </td> </tr> <!--footer start--> <!--footer end--> </table> <div> </div></form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/181646-need-help-submit-form-to-different-emailadds-dependent-on-location-chosen/ Share on other sites More sharing options...
mrMarcus Posted November 15, 2009 Share Posted November 15, 2009 you can just use an IF/ELSE or switch() statement to do this. <?php if ($_POST['courseLoc'] == 'asia') { $emailTo = '[email protected]'; } elseif ($_POST['courseLoc']) { $emailTo = '[email protected]'; } else { //no email address; } ?> -OR- <?php switch ($_POST['courseLoc']) { case 'asia': $emailTo = '[email protected]'; break; case 'america': $emailTo = '[email protected]'; break; //etc; default: //no email address; do something; break; } ?> of course, you need to add some more error handling to this, but this will work for you. Link to comment https://forums.phpfreaks.com/topic/181646-need-help-submit-form-to-different-emailadds-dependent-on-location-chosen/#findComment-958111 Share on other sites More sharing options...
chen2424 Posted November 15, 2009 Author Share Posted November 15, 2009 marcus, if else worked great for me. cheers! Link to comment https://forums.phpfreaks.com/topic/181646-need-help-submit-form-to-different-emailadds-dependent-on-location-chosen/#findComment-958119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.