Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Sending emails according checkbox

the mail() function

Moderators: macek, egami, gesf

Sending emails according checkbox

Postby suensh » Sun Oct 30, 2011 2:48 am

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 At the same time I want it to be sent to when user ticks Yes of "Caterers". When user ticks Photographers then also send this form to another email

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:

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.

Code: Select all
HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

<form method="post" action="form.php">
<table width="573" cellpadding="5" cellspacing="0" class="txt">

<td width="10" height="25" bgcolor="#cee39e">&nbsp;</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 width="107" bgcolor="#cee39e">&nbsp;</td>

<td height="25" bgcolor="#cee39e">&nbsp;</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 bgcolor="#cee39e">&nbsp;</td>
<td height="25" bgcolor="#cee39e">&nbsp;</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">&nbsp;</td>

<td height="25" bgcolor="#cee39e">&nbsp;</td>
<td height="25" colspan="2" valign="top" bgcolor="#cee39e" class="txt"><table width="456" cellpadding="10" cellspacing="0">


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

<td bgcolor="#cee39e">&nbsp;</td>

<td bgcolor="#cee39e">&nbsp;</td>
<td height="30" colspan="2" bgcolor="#cee39e">
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
<td bgcolor="#cee39e">&nbsp;</td>


PHP code:

$to = $_REQUEST[''] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Enquiries";

$fields = array();
$fields{"Name"} = "\nFull Name";
$fields{"Email"} = "\nEmail Address";
$fields{"suppliers"} = "\nI would like you guys supply";

$body = "Someone has sent the following enquiries:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From:";
$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(''),
"photographers" => array(''),
"bakers" => array(''),
"florists" => array('')


foreach($_REQUEST['suppliers'] as $value){foreach($recipient_email_addresses[$value] as $value2){
   mail($value2,$subject, $body, $headers);}}


if($from == '') {header( "Location:" );}
else {
if($name == '') {header( "Location:" );}
else {
$send = mail('', $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
{header( "Location:" );}
{print "We encountered an error sending your mail, please notify"; }
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Oct 24, 2011 9:13 pm

Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.