PDA

View Full Version : My PHP form is driving me crazy - please help!


airind
02-13-2011, 08:01 PM
After much fighting with PHP, I finally got my PHP to email me my form. However, when it emails me the email looks like this:

namephoneemail@email.comheardYesYes

So all of the fields email in one string on one line.
I have tried a few different coding options but it seems as soon as I do that it doesn't email me at all. Can someone please tell me how to get the email it sends to be formatted so I can actually tell the difference between the fields?

The PHP code
<code>
<?php
$event = $_POST['event'] ;
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$email = $_POST['email'] ;
$How_did_you_hear_about_us = $_POST['How_did_you_hear_about_us'] ;
$Updates = $_POST['Updates'] ;
$Terms = $_POST['Terms'] ;
$comments = $_POST['comments'] ;
mail( "info@tonedtraining.com",
"Registration",$message=$Event.$name.$phone.$email.$How_did_you_ hear_about_us.$Updates.$Terms.$comments, "From: $email" );
header( "Location: http://www.tonedtraining.com/thankyou.htm" );
?>
</code>

The form code
<code>
<form method="post" name="registration_form" action="registration.php"><!--
<input name="event" size="30" type="hidden" value="This Event Name" />
--><label>Event: <select name="Event"> <option selected
value=yogajan>Yoga</option></select></label><label class="highlight">Name: <input size="30"
name=name> </label><label>Phone: <input size="30" name="phone"> </label><label
class=highlight>Email: <input size="30" name="email"> </label><label>How did you
hear about us?<input size="30" name="How_did_you_hear_about_us"> </label>
<div class="radio_checkbox highlight padded"><input value="Yes" type="checkbox"
name=Updates[]> Would you like to receive e-mail updates? </div><!--<div class="radio_checkbox highlight padded">
Radio Buttons:<br />

<label>yes <input name="radio_buttons" value="yes" type="radio" /></label>

<label>no <input name="radio_buttons" value="no" type="radio" /></label>
</div>

<div class="radio_checkbox padded">
Check Boxes:<br /> --><!-- If using checkboxes be sure to include square brackets (ex. name="meal_selections[]") at the end of the name attribute --><!--<label>yes <input name="checkboxes[]" value="yes" type="checkbox" /></label>

<label>no <input name="checkboxes[]" value="no" type="checkbox" /></label>
</div>

<label class="highlight">-->
<div class="radio_checkbox padded"><!-- If using checkboxes be sure to include square brackets (ex. name="meal_selections[]") at the end of the name attribute --><input
value=Yes type=checkbox name=Terms> I have read and agree to all <a
href="terms.html (http://members.shaw.ca/girltalkevents/terms.html)" target=blank>Terms and
Conditions</a> (required for registration)</div><label
class=higlight>Questions/Comments: <textarea rows="4" cols="26" name="comments"></textarea> </label>
<div class="submit"><input value="submit" type="submit" name="submit_button">
</div></form>

</code>

davidj
02-15-2011, 06:07 AM
this is wrong...

mail("info@tonedtraining.com","Registration",$message=$Event.$name.$phone.$email.$How_did_you_ hear_about_us.$Updates.$Terms.$comme nts, "From: $email" );Here is the structure of the mail function with properties...

mail( string $to , string $subject , string $message, string $headers);Using that guide your structure should be like this...

$to = "info@tonedtraining.com";
$subject = "Registration";

$event = $_POST['event'] ;
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$email = $_POST['email'] ;
$hear = $_POST['How_did_you_hear_about_us'] ;
$updates = $_POST['Updates'] ;
$terms = $_POST['Terms'] ;
$comments = $_POST['comments'] ;

$message = "Event:" . $event . "\n\n";
$message .= "Name:" . $name. "\n\n";
$message .= "phone:" . $phone. "\n\n";
$message .= "Email:" . $email. "\n\n";
$message .= "How did you hear:" . $hear. "\n\n";
$message .= "Updates:" . $updates. "\n\n";
$message .= "Terms:" . $terms. "\n\n";
$message .= "Comments:" . $comments. "\n\n";

$header = "";

mail($to,$subject,$message,$header);

airind
02-23-2011, 02:01 AM
Thanks, davidj.
Unfortunately using this code didn't work - now it doesn't send any email at all again. I was confused at one thing - why would I want the header in the email? I was just using the header function to redirect once the submit button was hit (that part works fine).
Could it be a problem with my HTML?
I'll post my codes again, I'm seriously going insane.


<form onsubmit="return validate();" method="post" name="registration_form"
action=registration1.php><!--
<input name="event" size="30" type="hidden" value="This Event Name" />
--><label>Event: <select name="Event"> <option selected
value=yogajan>Hot Yoga</option><option
value=circus>Circus </option></select>
</label><label>Name:<input size="30" name="name"> </label><label>Phone: <input
size=30 name=phone> </label><label class="highlight">Email: <input size="30"
name=email> </label><label>How did you hear about us?<input size="30" name="heard">
</label>
<div class="radio_checkbox highlight padded"><input value="Yes" type="checkbox"
name=updates[]> Would you like to receive e-mail updates? </div><!--<div class="radio_checkbox highlight padded">
Radio Buttons:<br />

<label>yes <input name="radio_buttons" value="yes" type="radio" /></label>

<label>no <input name="radio_buttons" value="no" type="radio" /></label>
</div>

<div class="radio_checkbox padded">
Check Boxes:<br /> --><!-- If using checkboxes be sure to include square brackets (ex. name="meal_selections[]") at the end of the name attribute --><!--<label>yes <input name="checkboxes[]" value="yes" type="checkbox" /></label>

<label>no <input name="checkboxes[]" value="no" type="checkbox" /></label>
</div>

<label class="highlight">-->
<div class="radio_checkbox padded"><!-- If using checkboxes be sure to include square brackets (ex. name="meal_selections[]") at the end of the name attribute --><input
value=Yes type=checkbox name=terms> I have read and agree to all <a
href="terms.htm" target=blank>Terms and Conditions</a> </div><label
class=highlight>Questions/Comments: <textarea rows="4" cols="26" name="comments"></textarea> </label>
<div class="submit"><input value="submit" type="submit" name="submit_button">
</div></form></div></div>


and the php

<?php
$to = "info@tonedtraining.com";
$subject = "Registration";
$event = $_POST['event'] ;
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$email = $_POST['email'] ;
$hear = $_POST['heard'] ;
$updates = $_POST['updates[]'] ;
$terms = $_POST['terms'] ;
$comments = $_POST['comments'] ;
$message .= "Event:" . $event . "\n\n";
$message .= "Name:" . $name. "\n\n";
$message .= "phone:" . $phone. "\n\n";
$message .= "Email:" . $email. "\n\n";
$message .= "How did you hear:" . $hear. "\n\n";
$message .= "Updates:" . $updates. "\n\n";
$message .= "Terms:" . $terms. "\n\n";
$message .= "Comments:" . $comments. "\n\n";
header ("Location:http://www.tonedtraining.com/thankyou.htm");
mail($to, $subject, $message);
?>

davidj
02-23-2011, 10:28 AM
you are doing a header(location) before the mail has been sent

swap them round like this

mail($to, $subject, $message);
header ("Location:http://www.tonedtraining.com/thankyou.htm");
exit;