Page 1 of 1

Add choice of recipients to PHP form

Posted: Wed Jun 02, 2010 6:37 am
by MacGuyUK
I have a very simple PHP code which works very well for sending an online form to an email address. But i would like to give the user a choice of 4 different email addresses to send it to (just one to be selected). is this at all possible? please see the PHP and form codes below.

I'd be grateful for any help/suggestions.

Thank you.

PHP:

Code: Select all

<?php
$name = $_REQUEST['name'];
$address = $_REQUEST['address'];
$tel = $_REQUEST['tel'];
$email = $_REQUEST['email'];
$date = $_REQUEST['date'];

/*Sending Email*/

$to = "recipient1@domain.com";
$subject = "Online Form";
$message = "
This is the form

Date = $date
Name = $name
Address = $address
Tel = $tel
Email = $email";

$from = "$email";

if(mail($to, $subject, $message, "From: $from"))
echo "Thank you";
else
echo "Mail send failure - message not sent"; 
?>
THE FORM:
<form action="scripts/sendingemail.php" method="get" enctype="multipart/form-data" name="paymentform" class="style63" id="paymentform">
<table width="100%" border="0" cellspacing="5" cellpadding="0">

<tr>
<td colspan="3" valign="top" class="style63"><hr width="100%" size="1" noshade="noshade" /></td>
</tr>
<tr>
<td valign="middle" nowrap="nowrap" class="style63">1.</td>
<td valign="middle" nowrap="nowrap" class="style63">Company</td>
<td width="90%"><p>
<input name="name" type="text" class="style63" id="name" />
</p> </td>
</tr>


<tr>
<td valign="middle" class="style63">2.</td>
<td valign="middle" class="style63">Ordered by</td>
<td><input name="address" type="text" class="style63" id="address" value="" /></td>
</tr>

<tr>
<td valign="middle" class="style63">3.</td>
<td valign="middle" class="style63">Date</td>
<td><input name="cardnumber" type="text" class="style63" id="cardnumber" /></td>
</tr>

<tr>
<td valign="middle" class="style63">4.</td>
<td valign="middle" nowrap="nowrap" class="style63">Delivery method (from Larkin)</td>
<td><input name="cardname" type="text" class="style63" id="cardname" /></td>
</tr>
<tr valign="middle">
<td colspan="3" class="style63"><hr width="100%" size="1" noshade="noshade" /></td>
</tr>

<tr>
<td colspan="3" valign="top" class="style63"><hr width="100%" size="1" /></td>
</tr>
</table>
<label></label>
<div align="center"> </div>
<label class="style63"></label>
<label>
<div align="center">
<input name="Submit" type="submit" class="style63" id="Submit" value="Submit" />
</div>
</label>
<div align="center"><br />
</div>
<label class="style63"></label>
<br />
<label></label>
<label></label>
</form>

Re: Add choice of recipients to PHP form

Posted: Wed Jun 02, 2010 2:29 pm
by phdatabase
Just add this the the form

Code: Select all

<input type='radio' name='email' value='email1@g.com' />email1@g.com<br />
<input type='radio' name='email' value='email2@g.com' />email2@g.com<br />
<input type='radio' name='email' value='email3@g.com' />email3@g.com<br />
<input type='radio' name='email' value='email4@g.com' />email4@g.com<br />
and then get mail like the other variables.

As an aside, This is a very dangerous script to have out on the Internet. You'll be a spammer's best friend if anyone looking with less then legitimate intentions finds this. I suggest you spend some time investigating the security issues regarding forms and email. FYI.