naegling Posted June 24, 2008 Share Posted June 24, 2008 Hi all - Its my first post here, sorry if my question is covered somewhere else, I did my best at searching for a solution before posting... Here's my problem: I'm attempting to select a different email address for the completed HTML form to be sent to by the use of a radio button group. So... depending on which radio button " ['type_of_problem'] " is selected, it will send it to the appropriate person in charge of that area. Here's the code I have created, but I cant get it to select the addresses. Can someone give me a hint at what I'm doing wrong? Am I missing something in the "switch" section of code? Or perhaps not initializing my variables right? <?PHP $Sentto = $_POST['type_of_Problem']; $to = ""; switch ($Sentto) { Case "vehicle": $to = "[email protected]"; break; Case "RadioMDTPhone": $to = "[email protected]"; break; Case "PPE": $to = "[email protected]"; break; Case "Other": $to = "[email protected]"; break; } $subject = "Lebanon Fire District Maintanance Form Repair Request"; $headers = "From: Maint. Form Mailer"; $forward = 0; $location = ""; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; if ($_SERVER['REQUEST_METHOD'] == "POST") { foreach ($_POST as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } else { foreach ($_GET as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } mail($to, $subject, $msg, $headers); if ($forward == 1) { header ("Location:$location"); } else { echo "Thank you for submitting our form. Please inform Dispatch of any OUT OF SERVICE vehicles ( LCSO Non-Emergency 541-928-6911"; } ?> The form can be reached here if anyone is interested... http://naegling.com/Test/MaintForm.html * Note* This is hosted on a 1and1 Linux server I believe running PHP 5. I can get the form to run if I just initialize $to with one address and don't use the switch, but thats really not what I'm after... This is the first form I've ever made, so please be gentle. I'm a real noob at this. ??? ??? ??? Thanks for any help in advance, Brent Gaskey Firefighter/EMT Lebanon Fire District Link to comment https://forums.phpfreaks.com/topic/111633-can-i-select-a-different-email-address-through-the-use-of-a-switch/ Share on other sites More sharing options...
shelluk Posted June 24, 2008 Share Posted June 24, 2008 Can you add some echo statements in there just to echo $to and $Sentto to confirm what it thinks they are? Thanks, Shell Link to comment https://forums.phpfreaks.com/topic/111633-can-i-select-a-different-email-address-through-the-use-of-a-switch/#findComment-573046 Share on other sites More sharing options...
naegling Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks for the suggestion Shell, I'll do that. It's 1AM and I've been working on this all day... time to call it quits and sleep on it for tonight. Thanks again... Link to comment https://forums.phpfreaks.com/topic/111633-can-i-select-a-different-email-address-through-the-use-of-a-switch/#findComment-573048 Share on other sites More sharing options...
thebadbad Posted June 24, 2008 Share Posted June 24, 2008 Your problem lies in your naming of the radio buttons. You named them "Type of Problem", which is fine for all I know, but then you try to access the chosen value with $_POST['type_of_Problem']. Where did the underscores come from? And string/variables in PHP are also case sensitive, so only $_POST['Type of Problem'] can be used to access what you're looking for. It also seems like you will have some trouble with comparing the chosen value with the values in your switch statement, again because of case sensitivity. I.e. "Vehicle" isn't equal to "vehicle". So in general: The $_POST array always carries keys and values identical to the names and values of the form that submitted it. It's very important to be precise! Link to comment https://forums.phpfreaks.com/topic/111633-can-i-select-a-different-email-address-through-the-use-of-a-switch/#findComment-573062 Share on other sites More sharing options...
naegling Posted July 4, 2008 Author Share Posted July 4, 2008 It was all in the syntax... my bad. Thanks for all the help, you guys rock. Link to comment https://forums.phpfreaks.com/topic/111633-can-i-select-a-different-email-address-through-the-use-of-a-switch/#findComment-581977 Share on other sites More sharing options...
naegling Posted July 4, 2008 Author Share Posted July 4, 2008 BTW here's the code: <?PHP $email = $_POST['Type']; switch ($email){ case "Vehicle": $sentto = "[email protected]"; //echo "sent to vehicle"; break; case "PPE": $sentto = "[email protected]"; //echo "sent to PPE"; break; default: $sentto = "[email protected]"; //echo "sent to default"; break; } $to = $sentto; $subject = "Results from your Request Info form"; $headers = "From: Form Mailer"; $forward = 0; $location = ""; $date = date ("l, F jS, Y"); $time = date ("h:i A"); echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; $msg = "Below is the result of your feedback form. It was submitted on $date at $time."; if ($_SERVER['REQUEST_METHOD'] == "POST") { foreach ($_POST as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } else { foreach ($_GET as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } mail($to, $subject, $msg, $headers); if ($forward == 1) { header ("Location:$location"); } else { echo "blah blah blah. Sent to: $sentto, email: $email, to: $to NOTE blah blah blah"; } ?> Link to comment https://forums.phpfreaks.com/topic/111633-can-i-select-a-different-email-address-through-the-use-of-a-switch/#findComment-581981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.