prettikittie Posted July 16, 2009 Share Posted July 16, 2009 Hi, I do hope it's alright to begin another topic as this is different then my last issue (though resolved!). Think maybe I'm getting in a bit over my head here?! Lol In my form, I've a drop down menu with 5 different city locations ... I need to be able and send an email based on the city selected. For example: If they were to select Orange Grove, then I need the email to be sent to [email protected] If they select Mathis, I need the email to go to [email protected] and so on ... The following is what I have currently ... but I'm not clear on how to implement what I need done and can't seem to find anything via Google or such. (Hard to know what to type and search as well.) Thank you` <?php $EmailFrom = "$Name"; $EmailTo = "xxx"; $Subject = "xxx"; $locations= htmlspecialchars(Trim(stripslashes($_POST['Locations']))); $Name = htmlspecialchars(Trim(stripslashes($_POST['Name']))); $Phone = htmlspecialchars(Trim(stripslashes($_POST['Phone']))); $Email = htmlspecialchars(Trim(stripslashes($_POST['Email']))); $Message = htmlspecialchars(Trim(stripslashes($_POST['Message']))); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Location: "; $Body .= $Locations; $Body .= "\n"; $Body .= "Request: "; $Body .= $Request; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Link to comment https://forums.phpfreaks.com/topic/166237-email-sent-depending-on-option-from-drop-down-selected-in-form/ Share on other sites More sharing options...
Amtran Posted July 17, 2009 Share Posted July 17, 2009 Most of the code is good, there were a few problems: if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } You have to change some of those double quotes. So: if (!$validationOK) { print '<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">'; exit; } Same goes for the other meta redirects. Now for the email problem, simply do this: $EmailTo = str_replace(' ', '', strtolower($_POST['Locations'])) . '@' . str_replace(' ', '', strtolower($_POST['Locations'])) . '.com'; Link to comment https://forums.phpfreaks.com/topic/166237-email-sent-depending-on-option-from-drop-down-selected-in-form/#findComment-876791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.