Jump to content

Can I select a different email address through the use of a "switch"???


naegling

Recommended Posts

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, ;D

 

Brent Gaskey

Firefighter/EMT

Lebanon Fire District

 

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!

  • 2 weeks later...

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"; 

} 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.