Email based on value in drop down menu


#1

I am having issues with my page. I am trying to send a email to a different address based on the entry that my user submits.

Here is my form on my test page.

[code]

Test    

[/code]

here is the php code for my formdata page
[php]<?php
$con = mysql_connect(“localhost”,“test”,“test”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“test”, $con);

$sql=“INSERT INTO formdata (test)
VALUES (’$_POST[test]’)”;

if (!mysql_query($sql,$con))
{
die('Error: ’ . mysql_error());
}
echo “Your Information Was Successfully Posted”;

mysql_close($con);

if ($_POST[‘test’] ==“A”){

$to = "email@sample.com";
$subject = “Custom Form”;
$message = $_POST[‘test’] ;
$headers = “From: email@sample.com”;
$sent = mail($to, $subject, $message, $headers) ;
} else if ($_POST[‘test’] ==“B”){

$to = "email2@sample.com";
$subject = “Custom Form”;
$message = $_POST[‘test’] ;
$headers = “From: email@sample.com”;
$sent = mail($to, $subject, $message, $headers) ;
}
if($sent)
{print “

Your mail was sent successfully”; }
else
{print “

We encountered an error sending your mail”; }

?>[/php]


#2

Sorry forgot to add I am having issues getting the email to work. Regardless of the Text in the form it goes to the first email address listed with all submissions.


#3

I just noticed the issue!

if ($_POST['test'] == "A"){

had a extra space in it.


#4

So, did that extra space fix it? If not, what is it doing again?


#5

Yes the issue was resolved with the space.