Jump to content

Archived

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

bschultz

PHP Form Mail

Recommended Posts

I have a PHP form mail script that works just fine. Now, though, I need the user to be able to select the recipient. No, problem, just use a drop box and pass the address that way. WRONG. I want to be able to hide the email address (for obvious reasons) and I can't figure out the logic on how to hide it. I've tried passing a variable like this in the drop box:

[code]
<select size="1" name="recipient">
<option>Please Select Recipient</option>
<option value="$name1">First Person's Name</option>
<option value="$name2">Second Person's Name</option>
</select>
[/code]

And then declare the variable in the processing script this way:

[code]
  $recipient = $_REQUEST['recipient'];
   $name = $_REQUEST['name'];
  $address = $_REQUEST['address'];
    $city = $_REQUEST['city'];
  $state = $_REQUEST['state'];
    $country = $_REQUEST['country'];
    $email = $_REQUEST['email'];
  $question = $_REQUEST['question'];

$name1 = "address1@domain.com";
$name2 = "address2@domain.com";

mail ( "$recipient", "Subject",

  "Name: $name\n
  Address: $address\n
  City: $city\n
  State: $state\n
  Country: $country\n
  Question:$question\n",
  "From: $email" );
  
echo '<meta http-equiv=Refresh content=1;url="http://www.url.com/thankyou.php">';
?>
[/code]

But that didn't work...it left the $recipient variable blank. Where am I off in my logic for this to work? Thanks in advance for the help.

Brian

Share this post


Link to post
Share on other sites
On the second script, you're not actually doing anything with $name1 and $name2. All you are doing is passing the value sent from the form (i.e: nothing because $name1 and 2 have no value assigned to them in the 1st script so by default are blank).

In the 1st script, you need to actually put the names in the different <options> (hardcoded or even better by giving values to $name1 and $name2 and maybe getting the list from a database if you're feeling brave) and on the second script, using the same list that you used on script 1 have PHP get the name that was sent from the form and pick out the email address that it corresponds to.

Something like:
[code]
switch ($_REQUEST['recipient']) {
   case "joe bloggs": $recipient = "joe.bloggs@hismail.com"; break;
   case "jenny whoever": $recipient = "jenny.whoever@hermail.com"; break;
}
[/code]

[a href=\"http://www.tizag.com/phpT/switch.php\" target=\"_blank\"]This is a good site that I found and now use when my brain has a blank moment.[/a] It's easier that the PHP official website most of the time.

Hope that helps a bit.

Share this post


Link to post
Share on other sites
[!--quoteo(post=361878:date=Apr 5 2006, 02:59 AM:name=Napoleon001)--][div class=\'quotetop\']QUOTE(Napoleon001 @ Apr 5 2006, 02:59 AM) [snapback]361878[/snapback][/div][div class=\'quotemain\'][!--quotec--]

Something like:
[code]
switch ($_REQUEST['recipient']) {
   case "joe bloggs": $recipient = "joe.bloggs@hismail.com"; break;
   case "jenny whoever": $recipient = "jenny.whoever@hermail.com"; break;
}
[/code]

[a href=\"http://www.tizag.com/phpT/switch.php\" target=\"_blank\"]This is a good site that I found and now use when my brain has a blank moment.[/a] It's easier that the PHP official website most of the time.

Hope that helps a bit.
[/quote]

That did the trick...thanks.

Share this post


Link to post
Share on other sites

×

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.