I am trying to have a "Contact us" page with a drop down tab that you can select from 4 people to contact. I am trying to figure out how to link each one to a certin email address. I was only able to get it with one. Thanks for your help.

You will need to take the POST value for the drop-down and use that as the E-Mail to address in the mail function, preferably, use names without an @ or domain.com and use PHP to assign an email:

switch($_POST['attn']) {
case name1:
$to_email = "name1@domain.com";
break;
case name2:
$to_email = "name2@domain.com";
break;
default:
$to_email = "Address if email not selected";
}

Don't put the E-Mail address in the field on the form as this can be edited client-side and may compromise your script.

Hey, Thanks for the tips. I am trying to learn this for fun. I thought it would of been a little easier...lol Here is what I am trying to do now after your help... I am still not able to get it to send emails after clicking webmaster or general info. Any advice?
$from = "From: $visitormail\r\n";
switch($_POST) {
case Webmaster:$to_email = mail("erich.krauz@rgl-e.com", $subject, $message, $from);
break;
case General Info:$to_email = mail("krauz2@hotmail.com", $subject, $message, $from);
break;
default:$to_email = "krauz2@hotmail.com";}

In contact1.php, change the 'value' for each of the <option> tags in the select to a single word in lower case to make it easire, for example, webmaster, info, tech and rgl like so:

<select name="attn" size="1">
<option value="webmaster">Webmaster </option>
 <option value="info">General Info </option>
</select>

Then in the other file put:

switch($_POST['attn']) {
case Webmaster:
$to_email = "erich.krauz@rgl-e.com";
break;
case info:
$to_email = "krauz2@hotmail.com";
break;
default:
$to_email = "krauz2@hotmail.com";
}
mail($to_email, $subject, $message, $from);

It would also be a good idea to handle any errors thrown by the mail function like so:

@$send_email = mail($to_email, $subject, $message, $from);
if($send_email) {
echo "E-Mail sent successfully";
} else {
echo "The E-Mail was not sent.";
}

Thanks again, The email is getting sent reguardless of which option I pick. The only problem is, it keeps sending the defult email so i am guessing it is not seeing the first two options....?

Try de-capitalizing the W in webmaster, that was meant to be lower case

Attention:<br />
<select name="attn" size="1">
<option value=" webmaster ">Webmaster </option>
<option value=" info ">General Info </option>

Are you in England? If so, you are up pretty late..lol I was stationed there a few months ago at RAF Lakenheath

Does the script in your last posts work? As this seems to be correct.

Make sure you put your code in code-tags so that it displays correctly

Also, yes I am based in the UK, but I work nightshift as tech support in the US department of a PC company

I bet it is something small..lol It sends emails but to the default email address. It does not even see the web and info. This is what I've added. Thanks again for helping me out.

take out the space between the " and values in the form. so " webmaster " becomes "webmaster" you follow?

I think so...so like?
<select name = "attn" size = "1" >
<option value = "webmaster" > Webmaster </option>
<option value = "info" > General Info </option>

</select>

still nothin. What else do you think I can try besides a switch function?

What happens if you put the following into the PHP script:

echo $_POST['attn'];

wrap the switch and mail functions with /* and */ to prevent them running:

/*
switch($_POST['attn']) {

case webmaster:$to_email = "erich.krauz@rgl-e.com";
break;
case info:$to_email = "krauz2@hotmail.com";
break;
default:
$to_email = "erich.krauz@rgl-e.com";
}
mail($to_email, $subject, $message, $from);
*/
echo $_POST['attn'];

Also, I just noticed you previously had $attn = $_POST; so you would be able to replace $_POST with $attn in the switch statement.

It goes to my submitted page but does not send any emails

In the top left corner it shows info...(the option that was selected"

WheN i put it to webmaster it shows webmaster in the top left on my submitted page

does this look right?
switch($_POST) {

how else can I have it...I see it says $attn = $_POST

so would that mean...
switch[$attn]

My bad, put the values on the case statements in the switch in '':

switch($_POST['attn']) {
case 'webmaster':
$to_email = "erich.krauz@rgl-e.com";
break;
case 'info':
$to_email = "krauz2@hotmail.com";
break;
default:
$to_email = "erich.krauz@rgl-e.com";
}
mail($to_email, $subject, $message, $from);

You could also use switch($attn) {

It keeps goign to the defult email. I kept the echo in and it displays the correct choise in the upper left hand corrner. So it doesnt care which one i pick, it just sends it to default email. LOL whats going on with this

You could try using an IF rather than a switch:

if($attn == "webmaster") {
$to_email = "erich.krauz@rgl-e.com";
} elseif($attn == "info") {
$to_email = "krauz2@hotmail.com";
} else {
$to_email = "erich.krauz@rgl-e.com";
}

thanks for your help xan. I am going to mess around with it for a while and see what I can come up with. Thank you so much for all your help.

The variable $attn would only work if he has register_globals on, which is turned off by default in PHP => 4.3.0 since it is a security vulnerability.

krauz2, you can try something like:

$to_email = ($_POST['attn'] == "info") ? "krauz2@hotmail.com" : "erich.krauz@rgl-e.com";

Please check and make sure $_POST isn't empty:

if(empty($_POST['attn'])){die("Variable _POST['attn'] is empty for some reason.";} // demonstration purposes only.

No, check line 28 of his sendemail.php script:

$attn = $_POST['attn'];

Also, he has been echoing the attn value and it is printing the correct item.

commented: sorry mate +3

Ah, sorry, didn't read the script at all, I admit. It now comes to my attention that the code I posted above is totally irrelevant.

thanks for all your help. I was able to get the switch to work. I tried the attn instead of the other way and for some reason it worked. I tell you its a pretty good feeling when you see it work...lol
Erich

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.