Page 1 of 1

How To Send CHECK BOX data from a FORM to EMAIL

Posted: Tue Aug 31, 2010 2:58 am
by mozero
hello

I have created this QUOTATION form but i m not receiving the date from CHECK BOXES in the email. Can anyone Help?

HTML is as follows

<form action="php/quotation.php" method="post" name="quotation_form">
<label for="Name">Name:</label>
<input name="Name" type="text" size="30" />

<label for="Company">Company:</label>
<input name="Company" type="text" size="30" />

<label for="Phone">Phone:</label>
<input name="Phone" type="text" size="30" />

<label for="Fax">Fax:</label>
<input name="Fax" type="text" size="30" />

<label for="Email">Email:</label>
<input name="Email" type="text" size="30" />

<label for="Web">Web:</label>
<input name="Web" type="text" size="30" />

<label for="Inquiry">Inquiry Items:</label><br />
<input type="checkbox" name="Inquiry[]" value="greige" class="checkbox"> Greige Fabric
<input type="checkbox" name="Inquiry[]" value="finished" class="checkbox"> Finished Fabric
<input type="checkbox" name="Inquiry[]" value="home" class="checkbox"> Home Textiles
<input type="checkbox" name="Inquiry[]" value="garments" class="checkbox"> Garments <br />

<label for="Quantity">Quantity:</label>
<input name="Quantity" type="text" size="10" />

<label for="Terms">Terms:</label>
<input name="Terms" type="text" size="30" />

<label for="Port">Port:</label>
<input name="Port" type="text" size="30" />

<label for="Message">Message:</label><br />
<textarea name="Message" cols="40" rows="10"></textarea>

<input type="submit" name="submit" value="Submit" class="submit-button" />
<input type="reset" name="reset" value="Reset" class="submit-button" onClick="document.quotation_form.reset();return false" />
</form>

And PHP Code is as follows

<?php

$EmailTo = "luckytextile@luckytextilemills.biz";
$Subject = "Quotation From Website";
$Name = Trim(stripslashes($_POST['Name']));
$Company = Trim(stripslashes($_POST['Company']));
$Phone = Trim(stripslashes($_POST['Phone']));
$Fax = Trim(stripslashes($_POST['Fax']));
$Email = Trim(stripslashes($_POST['Email']));
$Web = Trim(stripslashes($_POST['Web']));
$Inquiry = Trim(stripslashes($_POST['Inquiry']));
$Quantity = Trim(stripslashes($_POST['Quantity']));
$Terms = Trim(stripslashes($_POST['Terms']));
$Port = Trim(stripslashes($_POST['Port']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Fax: ";
$Body .= $Fax;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Web: ";
$Body .= $Web;
$Body .= "\n";
$Body .= "Inquired Items:";
$Body .= $Inquiry;
$Body .= "\n";
$Body .= "Quantity: ";
$Body .= $Quantity;
$Body .= "\n";
$Body .= "Terms: ";
$Body .= $Terms;
$Body .= "\n";
$Body .= "Port: ";
$Body .= $Port;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=../thanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=../error.html\">";
}
?>

Thanks

Re: How To Send CHECK BOX data from a FORM to EMAIL

Posted: Tue Aug 31, 2010 4:45 am
by cpetercarter
Your checkboxes have the name "Inquiry[]". That means that the POST variable $_POST['inquiry'] is an array (of the values returned from the checkboxes) and not a simple scalar variable.Even if the user checks only one of the boxes, the value of the checkbox will be at $_POST['Inquiry'][0], not $_POST['Inquiry']. So you need to loop through the $_POST['Inquiry'] array and add each element separately to the body of the email.

Re: How To Send CHECK BOX data from a FORM to EMAIL

Posted: Tue Aug 31, 2010 5:57 am
by mozero
hello

thanks for your reply. I tried to read the values via LOOP but didnt get anythin in email . could u plz help me in the coding of that loop and assigning the values to the Body element?

thanks

Muzaffar Uddin

Re: How To Send CHECK BOX data from a FORM to EMAIL

Posted: Tue Aug 31, 2010 6:00 am
by mozero
I used this PHP code for it

foreach($_POST['Inquiry'] as $value) {
$Check_Msg .= "Checked: $value\n";
}

now i am not getting as how i would post the result to the BODY element

thanks

Re: How To Send CHECK BOX data from a FORM to EMAIL

Posted: Wed Sep 01, 2010 1:05 am
by cpetercarter
Try this:

Code: Select all

<?php

$EmailTo = "luckytextile@luckytextilemills.biz";
$Subject = "Quotation From Website";
$Name = trim(stripslashes($_POST['Name']));
$Company = trim(stripslashes($_POST['Company']));
$Phone = trim(stripslashes($_POST['Phone']));
$Fax = trim(stripslashes($_POST['Fax']));
$Email = trim(stripslashes($_POST['Email']));
$Web = trim(stripslashes($_POST['Web']));
$inquiry = array();
if (isset($_POST['Inquiry']))  // if no check boxes are checked, $_POST['Inquiry'] will not exist
{
    foreach ($_POST['Inquiry'] as $value)
    {
        $inquiry[] = trim(stripslashes($value));
    }
}
$Quantity = trim(stripslashes($_POST['Quantity']));
$Terms = trim(stripslashes($_POST['Terms']));
$Port = trim(stripslashes($_POST['Port']));
$Message = trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Fax: ";
$Body .= $Fax;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Web: ";
$Body .= $Web;
$Body .= "\n";
$Body .= "Inquired Items: ";
if (empty($inquiry)) 
{
    $Body .= 'none';
}  else  {
    foreach ($inquiry as $item)
    {
        $Body .= $item . "&nbsp;";
    }
}
$Body .= "\n";
$Body .= "Quantity: ";
$Body .= $Quantity;
$Body .= "\n";
$Body .= "Terms: ";
$Body .= $Terms;
$Body .= "\n";
$Body .= "Port: ";
$Body .= $Port;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=../thanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=../error.html\">";
}
?>