Email Script - test radio buttons

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fiorano_2009
Forum Newbie
Posts: 1
Joined: Fri Sep 11, 2009 3:49 am

Email Script - test radio buttons

Post by fiorano_2009 »

Hi,

I have the following code to send an email after a form submission:

Code: Select all

<?
$destination="website@here.com";
$name=$_POST['name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$from = $_POST['email'];
$mes=$_POST['message'];
$header="From: $from\n";
$mes="Name: $name\n
Phone: $phone\n
Email: $email\n
Message: $mes\n";
mail($destination,"Web Enquiry",$mes,$header); header( "Location: http://www.here.com/thankyou.html" ); ?>
 
This is working fine.

Ive added four radio buttons to the form :
Rad1, Rad2,Rad3,Rad4
and depending on which buttons are selected I need to send the response to two different emails eg,

if Rad1 or Rad2 is selected then send the email to email1@here.com
else
if Rad3 or Rad4 is selected then send the email to email2@here.com

Is this possible??

Many thanks for any help,

Fiorano
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Email Script - test radio buttons

Post by Weiry »

well you would have to submit the data through post to itself ( $_SERVER['PHP_SELF'] )
but you could do it something like

Code: Select all

<input type='radio' value='1' name='radioSelect' /> Option 1
<input type='radio' value='1' name='radioSelect' /> Option 2
<input type='radio' value='2' name='radioSelect' /> Option 3
<input type='radio' value='2' name='radioSelect' /> Option 4
then when you want to check which email to send it to

Code: Select all

if($_POST['radioSelect']==1){
   // send to email 1
}elseif($_POST['radioSelect']==2){
   // send to email 2
}else{
   // give your error here
}
Post Reply