Email Form - Checkbox help

Reply

Join Date: Jul 2008
Posts: 86
Reputation: jhonnyboy is an unknown quantity at this point 
Solved Threads: 0
jhonnyboy jhonnyboy is offline Offline
Junior Poster in Training

Email Form - Checkbox help

 
0
  #1
Dec 23rd, 2008
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>&nbsp;</p>
  <p><img src="proposalssign.jpg" width="92" height="29" />
    </p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</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 />
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 20
Reputation: manish.s is an unknown quantity at this point 
Solved Threads: 1
manish.s manish.s is offline Offline
Newbie Poster

Re: Email Form - Checkbox help

 
0
  #2
Dec 23rd, 2008
  1. $service = $_POST['service'];
  2.  
  3. if(is_array($service))
  4. {
  5. $comma = "";
  6. $service_type = "";
  7.  
  8. foreach($service as $value)
  9. {
  10. $service_type .= $comma.$value;
  11. $comma = ", ";
  12. }
  13.  
  14. $message .= "Type of Service needed:" .$service_type . "\n";
  15. }


Same for other check boxes...
-- Manish Singh
manish.s@neuralit.com
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Email Form - Checkbox help

 
0
  #3
Dec 23rd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 20
Reputation: manish.s is an unknown quantity at this point 
Solved Threads: 1
manish.s manish.s is offline Offline
Newbie Poster

Re: Email Form - Checkbox help

 
0
  #4
Dec 23rd, 2008
Optimized code...

  1. $service = $_POST['service'];
  2.  
  3. if(is_array($service))
  4. {
  5. $message .= "Type of Service needed:" .implode(", ",$service). "\n";
  6. }
Last edited by manish.s; Dec 23rd, 2008 at 12:11 pm.
-- Manish Singh
manish.s@neuralit.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 86
Reputation: jhonnyboy is an unknown quantity at this point 
Solved Threads: 0
jhonnyboy jhonnyboy is offline Offline
Junior Poster in Training

Re: Email Form - Checkbox help

 
0
  #5
Dec 23rd, 2008
thank you so much guys. You are the best got another question...is there anyway i can direct them to a "thank you page" instead of echoing a message?
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 20
Reputation: manish.s is an unknown quantity at this point 
Solved Threads: 1
manish.s manish.s is offline Offline
Newbie Poster

Re: Email Form - Checkbox help

 
0
  #6
Dec 23rd, 2008
try this...

  1. $mail_sent = mail($to, $subject, $message, $headers);
  2.  
  3. if($mail_sent)
  4. {
  5. header("location:thankyou.php");
  6. }
-- Manish Singh
manish.s@neuralit.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 86
Reputation: jhonnyboy is an unknown quantity at this point 
Solved Threads: 0
jhonnyboy jhonnyboy is offline Offline
Junior Poster in Training

Re: Email Form - Checkbox help

 
0
  #7
Dec 23rd, 2008
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:

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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Email Form - Checkbox help

 
0
  #8
Dec 23rd, 2008
Remove echo "The Email Has Been Sent"; . The header has to be the first thing sent to the browser.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 86
Reputation: jhonnyboy is an unknown quantity at this point 
Solved Threads: 0
jhonnyboy jhonnyboy is offline Offline
Junior Poster in Training

Re: Email Form - Checkbox help

 
0
  #9
Dec 23rd, 2008
It gives me this error:


Warning: Cannot modify header information - headers already sent by (output started at /home/jebgroup/public_html/proposal.php:6) in /home/jebgroup/public_html/proposal.php on line 66
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Email Form - Checkbox help

 
0
  #10
Dec 23rd, 2008
Yes, you can't echo or print anything prior to using header. Headers can only be sent once. If you have any output to the browser, headers are sent. Then when you try to send more headers, you get errors.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC