I have a series of 5 checkboxes installed in a web form. I have the code to get the checkboxes to echo back onto a confirmation page for the site visitor to see. However I can't get the info to come back to me in the email. I don't know what code to insert into the $msg for the $servicename checkboxes to come to me in email. The closest I've gotten has been to get the email to tell me that there is an array, but it doesn't tell me the checked components of the array.

Here is my PHP code.

$service=$_POST['service'];
(I have omitted the other variables to save space here)


$to = 'amisenheimer@hotmail.com';
$subject = 'Inquiry';
$msg = "$name would like to be contacted by you.\n" .
	"Phone number: $phone.\n" .
	"Mailing Address: $address.\n" . 
	"City/State/Zip Code: $citystatezip.\n" .
	"Other comments: $other"; 
mail($to, $subject, $msg, 'From: ' . $email);

echo 'Thanks ' . $name . ' for submitting your information.<br />';
echo 'Your email address is ' . $email . '.<br />';
echo 'Your phone number is ' . $phone . '.<br />';
echo 'Your mailing address is ' . $address . ', ' . $citystatezip . '.<br />';
foreach ($service as $servicename)
{
echo "$servicename is checked. ";
}
echo '<br />You added the following information: ' . $other . '<br /><br />'; 


?>
print "<pre>";
print_r($_POST['checkbox_element_name'];
print "</pre>";

Does it print anything ? There is nothing wrong in your code except the checkbox name may be wrong :)

Edit: And a thumbs up for using [code] tags in your first post You should close the tag correctly next time. :)

Edited 3 Years Ago by Dani: Formatting fixed

I may not have been clear with my question. The echo function is working correctly and the mail function is also working correctly.

I am concatenating multiple strings into a single string as part of a reply email. This comes to me as part of $msg. My checkbox is using the variable $service. In the echo function I used foreach to make it display each of the items in the array (based on the checked boxes) that were selected.

However in the concatenated string how do I include the checkbox variable "$servicename" (see the echo function to see why I am using $servicename instead of $service) so that it will display all checked results? I re-ordered my php code to have the echo before the mail function. Currently in the email it only lists the last of the checked boxes as selected.

My code is below. I will include a bit of the HTML as well so that maybe my question can be taken in context. This is probably something very simple but I am new to php. Thanks!

HTML
      <label>
        <input type="checkbox" name="service[]" value="Logo Design" />
        Logo Design</label>
      <br />
      <label>
        <input type="checkbox" name="service[]" value="Copywriting" />
        Copywriting</label>
      <br />
      <label>
        <input type="checkbox" name="service[]" value="Branding" />
        Branding</label>

I will include the PHP since I made a couple changes to the original.

<?php


$service=$_POST['service']; (this is the variable in question)



echo 'Thanks ' . $name . ' for submitting your information.<br />';
echo 'Your email address is ' . $email . '.<br />';
echo 'Your phone number is ' . $phone . '.<br />';
echo 'Your mailing address is ' . $address . ', ' . $citystatezip . '.<br />';
foreach ($service as $servicename)
{
echo "$servicename is checked. ";
}
echo '<br />You added the following information: ' . $other . '<br /><br />'; 
echo 'Aaron will contact you soon to discuss what Urban Cattle Design Co. can do for you.';


$to = 'amisenheimer@hotmail.com';
$subject = 'Urban Cattle Inquiry';
$msg = "$name would like to be contacted by you.\n" .
	"Phone number: $phone.\n" .
	"Mailing Address: $address.\n" . 
	"City/State/Zip Code: $citystatezip.\n" .
	"$servicename checked.\n" .  
	"Other comments: $other"; 
mail($to, $subject, $msg, 'From: ' . $email);
?>
$services = implode(",",$_POST['service']);
//This will combine the array $_POST['service'] and form a string
Use it in $msg. 
$msg = $services." are the services which are checked\n";

Clear enough ?

This question has already been answered. Start a new discussion instead.