jkeen Posted October 6, 2007 Share Posted October 6, 2007 Hello i need some great person to help me out a little I have been trying to take the information from a form on the webpage and email it to my email address i am just trying to make a simple form to email script and it is working to send the mail but it is only sending part of the form information like 2-3 items. i have tried adding / removing fields from the form itself and from the form.php i made and everything ive tried just gives me the same result. here is what im working with. form.html <center><p><form action="form.php" method="POST"> Name: <input type="text" name="name" value=""> <br>Email: <input type="text" name="email" value=""> <br>Dates: <input type="text" name="date" value=""> <br>Subject: <input type="text" name="subject" value=""> <br>Message: <textarea name="message"></textarea> <br><input type="submit" name="submit" value="send"> </form></center> form.php <?php $to = "myemail@yahoo.com"; $subject = $_POST['subject']; $body = "What date or dates would you like to setup: ".$_POST['date']."\n"; $body = "Name: ".$_POST['name']."\n"; $body .= "From: ".$_POST['email']."\n"; $body .= "Message: ".$_POST['message']."\n"; if (@mail($to,$subject,$body)) { //Thank you message } else { //Error message } ?> this is what i get from the above in a email Name: joe From: myemail@yahoo.com Message: testing form It also puts the subject i enter into the subject line of the email the problem is that it didnt place the dates i enter in the form into the email or any other questions i might want to add to the form its like there is a limitation to how many things i can send through it. can anyone see what the problem is i would appreciate whatever help i can get i am not a php programmer but i am trying as hard as i can to figure this out and coming up with nothing. also it gives me this if i uncomment the thank you and error lines in the php Parse error: syntax error, unexpected T_STRING in /home/kittenbr/public_html/form.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/72095-solved-need-help-with-sending-form-data-to-email/ Share on other sites More sharing options...
MasterACE14 Posted October 6, 2007 Share Posted October 6, 2007 Your best to put the $_POST's into common variables before putting it into the body, subject, to etc etc. And I believe your missing a period. <?php // common variables $post_subject = $_POST["subject"]; $post_date = $_POST["date"]; $post_name = $_POST["name"]; $post_email = $_POST["email"]; $post_message = $_POST["message"]; $to = "myemail@yahoo.com"; $subject = $post_subject; $body = "What date or dates would you like to setup: ".$post_date."\n"; $body .= "Name: ".$post_name."\n"; // forgot the period before the equals sign at the beginning. $body .= "From: ".$post_email."\n"; $body .= "Message: ".$post_message."\n"; if (@mail($to,$subject,$body)) { //Thank you message // you could either echo/print a message, or redirect them to another page print "Thankyou"; // or header("Location: http://www.yoursite.com/thankyou.php"); } else { //Error message // same goes for this one, print or redirect print "Their was an Error"; // or header("Location: http://www.yoursite.com/error.php"); } ?> you can also remove all the value="" in the form page. They aren't required. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/72095-solved-need-help-with-sending-form-data-to-email/#findComment-363350 Share on other sites More sharing options...
jkeen Posted October 6, 2007 Author Share Posted October 6, 2007 thank you i knew it had to be something simple lol you are great Quote Link to comment https://forums.phpfreaks.com/topic/72095-solved-need-help-with-sending-form-data-to-email/#findComment-363633 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.