| | |
Email Form - Checkbox help
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 86
Reputation:
Solved Threads: 0
hey guys, im a bit new to php. I was wondering if any of you guys could help me out with this email code i have to send me an email. I have a website with a service link then the user needs to pick which kind of service he/she requires. Everything works except the checkbox part. It sends me an email and it's blank there. Here is my code:
<?
include("../header.php");
$name= $_POST['name'];
$from = $_POST["email"];
$to = "je@example.com";
$subject = "Proposal Request";
$message = "Company Name: " . $_POST["companyname"] . "\n";
$message .= "Telephone Number:" . $_POST["telephonenumber"] . "\n";
$message .= "Email Address:" . $_POST["email"] . "\n";
$message .= "Company Name:" . $_POST["companyname"] . "\n";
$message .= "Company Address:" . $_POST["location"] . "\n";
$message .= "City:" . $_POST["city"] . "\n";
$message .= "State:" . $_POST["state"] . "\n";
$message .= "Type of Service needed:" . $_POST["service[]"] . "\n";
$message .= "Best Time to Contact:" . $_POST["time[]"] . "\n";
$message .= "Contact by Email/Phone:" . $_POST["cpref[]"] . "\n";
if($sent){
$headers = 'From: ' . $name . ' <' . $from . '>' . "\r\n" .
'Reply-To: ' . $from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo "The Email Has Been Sent";
}
?>
<div style="position: absolute; left:149px; top:320px;">
<table bgcolor="#ffffff" width="800" border="0">
<tr>
<td>
<div align="center">
<p> </p>
<p><img src="proposalssign.jpg" width="92" height="29" />
</p>
</div>
<p> </p>
<p> </p>
<table width="680" border="0" align="center">
<tr>
<td>Need a Free Quote for your company? Not a problem just fill out the indicated boxes below, and we'll be sure to give you a call within the next 24 hours. </td>
</tr>
</table>
<p>
<!-- Begin Proposal Form -->
<form enctype="multipart/form-data" method="post" action="proposal.php" accept-charset="UTF-8">
<input type="hidden" name="sent" value="1" />
<table cellspacing="5" cellpadding="5" border="0">
<tr>
<td valign="top">
<strong>Name:</strong>
</td>
<td valign="top">
<input type="text" name="name" id="name" size="40" value="" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Telephone Number:</strong>
</td>
<td valign="top">
<input type="text" name="telephonenumber" id="telephonenumber" size="40" value="" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Email Address:</strong>
</td>
<td valign="top">
<input type="text" name="email" id="email" size="40" value="" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Company Name:</strong>
</td>
<td valign="top">
<input type="text" name="companyname" id="companyname" size="40" value="" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Company Address:</strong>
</td>
<td valign="top">
<input type="text" name="location" id="location" size="40" value="" />
</td>
</tr>
<tr>
<td valign="top">
<strong>City:</strong>
</td>
<td valign="top">
<input type="text" name="city" id="city" size="40" value="" />
</td>
</tr>
<tr>
<td valign="top">
<strong>State:</strong>
</td>
<td valign="top">
<input type="text" name="state" id="state" size="40" value="" />
</td>
</tr>
<tr>
<td valign="top">
<strong>What kind of service are you looking for?</strong>
</td>
<td valign="top">
<input type="checkbox" name="service[]" id="service_0" value="One-Time Scrub Down" /> One-Time Scrub Down<br/>
<input type="checkbox" name="service[]" id="service_1" value="Daily Maintenance" /> Daily Maintenance<br/>
<input type="checkbox" name="service[]" id="service_2" value="Weekend Maintenance" /> Weekend Maintenance<br/>
</td>
</tr>
<tr>
<td valign="top">
<strong>What's the best time to contact you at?</strong>
</td>
<td valign="top">
<input type="checkbox" name="time[]" id="time_0" value="Morning" />Morning<br/>
<input type="checkbox" name="time[]" id="time_1" value="Afternoon" />Afternoon<br/>
<input type="checkbox" name="time[]" id="time_2" value="Evening" />Evening<br/>
</td>
</tr>
<tr>
<td valign="top">
<strong>What is the preferred method to contact you?</strong>
</td>
<td valign="top">
<input type="checkbox" name="cpref[]" id="cpref_0" value="Email" />Email<br/>
<input type="checkbox" name="cpref[]" id="cpref_1" value="Phone" />Phone<br/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value=" Submit Form " />
</td>
</tr>
</table>
</form>
<!-- End Proposal Form --><br /><br />•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
PHP Syntax (Toggle Plain Text)
$service = $_POST['service']; if(is_array($service)) { $comma = ""; $service_type = ""; foreach($service as $value) { $service_type .= $comma.$value; $comma = ", "; } $message .= "Type of Service needed:" .$service_type . "\n"; }
Same for other check boxes...
-- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
Looks like manish.s beat me too it. Just remember that your checkbox group is an array, and they have to be extracted with a loop. Also, a radio button may be better for the service if you only want one possible value.
Last edited by buddylee17; Dec 23rd, 2008 at 12:08 pm.
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
Optimized code...
PHP Syntax (Toggle Plain Text)
$service = $_POST['service']; if(is_array($service)) { $message .= "Type of Service needed:" .implode(", ",$service). "\n"; }
Last edited by manish.s; Dec 23rd, 2008 at 12:11 pm.
-- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
try this...
PHP Syntax (Toggle Plain Text)
$mail_sent = mail($to, $subject, $message, $headers); if($mail_sent) { header("location:thankyou.php"); }
-- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
•
•
Join Date: Jul 2008
Posts: 86
Reputation:
Solved Threads: 0
ok i implimented that into the code i had already, but it didn't work. It gave me an error. This is what i did:
btw what does the X-Mailer thing mean? Thanks again guys!
if($sent){
$headers = 'From: ' . $name . ' <' . $from . '>' . "\r\n" .
'Reply-To: ' . $from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo "The Email Has Been Sent";
header("location:thankyou.php");
}btw what does the X-Mailer thing mean? Thanks again guys!
![]() |
Similar Threads
- Form Validation-Alert box (JavaScript / DHTML / AJAX)
- To send Email to Selected Checkbox is not Working in PHP thru Mysql; Pls Help (PHP)
- problems with Form in dreamweaver (IT Professionals' Lounge)
- Email Form ? (HTML and CSS)
- asp:repeater in a form? (ASP.NET)
- How to pre-select checkboxes in form? (PHP)
- cannot get the sendmail to actualy send an email with the form selections (PHP)
- Javascript, Form fields validation and submit (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: php mysql drop down list
- Next Thread: phpmyadmin displays error
| Thread Tools | Search this Thread |
advanced apache api array basics beginner binary broken cakephp check checkbox class cms code codingproblem combobox cookies cron curl database date datepart display dynamic echo email error file files folder form forms function functions google head href htaccess html image include includingmysecondfileinthechain insert ip javascript job joomla js limit link login mail menu mlm mobile multiple mysql oop outofmemmory paging parse password paypal pdf php problem procedure query radio random recursion remote script search server sessions smarty sms soap source space sql stored syntax system table traffic tutorial unicode up-to-date update upload url validator variable video web webapplications xml youtube






got another question...is there anyway i can direct them to a "thank you page" instead of echoing a message?