Jump to content


Photo

PHP Form Mail


  • Please log in to reply
2 replies to this topic

#1 bschultz

bschultz
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts
  • LocationMinnesota, USA

Posted 04 April 2006 - 06:25 PM

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:

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

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

  $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">';
?>

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

#2 Napoleon001

Napoleon001
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 April 2006 - 07:59 AM

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:
switch ($_REQUEST['recipient']) {
   case "joe bloggs": $recipient = "joe.bloggs@hismail.com"; break;
   case "jenny whoever": $recipient = "jenny.whoever@hermail.com"; break;
}

[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.

#3 bschultz

bschultz
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts
  • LocationMinnesota, USA

Posted 05 April 2006 - 12:27 PM

[!--quoteo(post=361878:date=Apr 5 2006, 02:59 AM:name=Napoleon001)--][div class=\'quotetop\']QUOTE(Napoleon001 @ Apr 5 2006, 02:59 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]

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

[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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users