943,648 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3172
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 23rd, 2008
0

Email Form - Checkbox help

Expand Post »
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 />
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
jhonnyboy is offline Offline
97 posts
since Jul 2008
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

PHP Syntax (Toggle Plain Text)
  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...
Reputation Points: 10
Solved Threads: 5
Light Poster
manish.s is offline Offline
29 posts
since Dec 2008
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

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.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

Optimized code...

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 5
Light Poster
manish.s is offline Offline
29 posts
since Dec 2008
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

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?
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
jhonnyboy is offline Offline
97 posts
since Jul 2008
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

try this...

PHP Syntax (Toggle Plain Text)
  1. $mail_sent = mail($to, $subject, $message, $headers);
  2.  
  3. if($mail_sent)
  4. {
  5. header("location:thankyou.php");
  6. }
Reputation Points: 10
Solved Threads: 5
Light Poster
manish.s is offline Offline
29 posts
since Dec 2008
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

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!
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
jhonnyboy is offline Offline
97 posts
since Jul 2008
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

Remove echo "The Email Has Been Sent"; . The header has to be the first thing sent to the browser.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

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
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
jhonnyboy is offline Offline
97 posts
since Jul 2008
Dec 23rd, 2008
0

Re: Email Form - Checkbox help

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.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php mysql drop down list
Next Thread in PHP Forum Timeline: AOL block emails created from my server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC