Hi guys,
I am trying to setup a form using array, however I got stuck there, would you please have a look for me?
I have a form using checkbox, this form will always submit to the admin, for example to admin@bigpond.com. At the same time I want it to be sent to email1@bigpond.com when user ticks Yes of “Caterers”. When user ticks Photographers then also send this form to another email email1@bigpond.com…etc.
I managed to send the form to admin, also to “Caterers” email address. However, on the submit email, just showing these:
Someone has sent the following enquiries:
Full Name: ABC
Email Address: user@bigpond.com
I would like you guys supply: Array
Line 1 to 3 are what I want, but on line 4, it is only showing “Array”, I want it to show Caterers, Photographers, Bakers, Florists if they are all ticked by user. Then the admin will know what the user actually order. Once again, the form will also send to different related department with their own email address according to the checkbox.
I just can’t figure out what I should do, would anyone please check on my setting?
Please help. Many many many thanks.
HTML code:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8” />
<title>Untitled Document</title>
</head>
<body>
<form method=“post” action=“form.php”>
<table width=“573” cellpadding=“5” cellspacing=“0” class=“txt”>
<tr>
<td width=“10” height=“25” bgcolor=“#cee39e”> </td>
<td width=“149” height=“25” valign=“middle” bgcolor=“#cee39e” class=“txt”><span class=“txtbold”>Your Full Name</span><span class=“txtred”>*</span></td>
<td width=“265” height=“25” bgcolor=“#cee39e”>
<input name=“Name” type=“text” size=“35” maxlength=“40” />
</td>
<td width=“107” bgcolor=“#cee39e”> </td>
</tr>
<tr>
<td height=“25” bgcolor=“#cee39e”> </td>
<td height=“25” valign=“middle” bgcolor=“#cee39e” class=“txt”><span class=“txtbold”>Email </span><span class=“txtred”>*</span></td>
<td height=“25” bgcolor=“#cee39e”>
<input name=“Email” type=“text” size=“35” maxlength=“50” />
</td>
<td bgcolor=“#cee39e”> </td>
</tr><tr>
<td height=“25” bgcolor=“#cee39e”> </td>
<td height=“25” colspan=“2” valign=“middle” bgcolor=“#cee39e” class=“txt”><span class=“txtbold”>What would you like us to supply:</span><span class=“txtred”></span></td>
<td bgcolor=“#cee39e”> </td>
</tr>
<tr>
<td height=“25” bgcolor=“#cee39e”> </td>
<td height=“25” colspan=“2” valign=“top” bgcolor=“#cee39e” class=“txt”><table width=“456” cellpadding=“10” cellspacing=“0”>
<tr>
<td width=“212” height=“20”><span class=“txtbold”>Caterers</span><span class=“txt”></span></td>
<td width=“202” height=“20”><input type=“checkbox” name=“suppliers” value=“caterers”>
<span class=“txt”> Yes</span></td>
</tr>
<tr>
<td width=“212” height=“20”><span class=“txtbold”>Photographers</span></td>
<td width=“202” height=“20”><input type=“checkbox” name=“suppliers” value=“photographers”>
<span class=“txt”> Yes</span></td>
</tr>
<tr>
<td width=“212” height=“20”><span class=“txtbold”>Bakers</span></td>
<td width=“202” height=“20”><input type=“checkbox” name=“suppliers” value=“bakers”>
<span class=“txt”> Yes</span></td>
</tr>
<tr>
<td width=“212” height=“20”><span class=“txtbold”>Florists</span></td>
<td width=“202” height=“20”><input type=“checkbox” name=“suppliers” value=“florists”>
<span class=“txt”> Yes</span></td>
</tr>
</table></td>
<td bgcolor=“#cee39e”> </td>
</tr>
<tr>
<td bgcolor=“#cee39e”> </td>
<td height=“30” colspan=“2” bgcolor=“#cee39e”>
<input type=“submit” name=“submit” value=“Submit” />
<input type=“reset” name=“reset” value=“Reset” />
</td>
<td bgcolor=“#cee39e”> </td>
</tr>
</table>
</form>
</body>
</html>
PHP code:
<?php
$to = $_REQUEST[‘admin@bigpond.com’] ;
$from = $_REQUEST[‘Email’] ;
$name = $_REQUEST[‘Name’] ;
$headers = “From: $from”;
$subject = “Enquiries”;
$fields = array();
$fields{“Name”} = "
Full Name";
$fields{“Email”} = "
Email Address";
$fields{“suppliers”} = "
I would like you guys supply";
$body = "Someone has sent the following enquiries:
“; foreach($fields as $a => $b){ $body .= sprintf(”%20s: %s
",$b,$_REQUEST[$a]); }
$headers2 = “From: admin@bigpond.com”;
$subject2 = “Thank you for contacting us”;
$autoreply = "Thank you, your enquiry has been received.
The team will get back to you asap.";
if(isset($_REQUEST[‘suppliers’]) && count($_REQUEST[‘suppliers’]))
{
$recipient_email_addresses = array
(
“caterers” => array(‘email1@bigpond.com’),
“photographers” => array(‘email2@bigpond.com’),
“bakers” => array(‘email3@bigpond.com’),
“florists” => array(‘email4@bigpond.com’)
);
foreach($_REQUEST[‘suppliers’] as $value){foreach($recipient_email_addresses[$value] as $value2){
mail($value2,$subject, $body, $headers);}}
}
if($from == ‘’) {header( “Location: http://www.company.com.au/pages/failure.html” );}
else {
if($name == ‘’) {header( “Location: http://www.company.com.au/pages/failure.html” );}
else {
$send = mail(‘admin@bigpond.com’, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( “Location: http://www.company.com.au/pages/thankyou.html” );}
else
{print “We encountered an error sending your mail, please notify admin@bigpond.com”; }
}
}
?>