gal Posted April 21, 2009 Share Posted April 21, 2009 Hello, Im new to the forum. I have a small problem which should not trouble most of you but will help me out alot. I have been given a simple form to mail example which I have working from my host. only problem is I dont know how to add extra form boxes to the php I have been given to me and have it displayed correctly in an email message. I need about 6 other form fields which I need to have stacked up in the email. (seperate lines) any help would be great. thanks in advance :-) here is my form from streamline.net: <FORM method=post action="contact.php"> Email: <br><INPUT name="email" type="text"><br> Message:<br> <TEXTAREA name="message" style="width:500px; height:150px" > </textarea><br> <input type=submit> </FORM> here is the php <?php mail("info@mysite.co.uk", "Feedback Form results", $_REQUEST[message], "From: $_REQUEST[email]", "-f".$_REQUEST[email]); header( "Location: index/thankyou.html" ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/ Share on other sites More sharing options...
AdRock Posted April 21, 2009 Share Posted April 21, 2009 Have a look here http://www.ibdhost.com/contact/ Quote Link to comment https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/#findComment-815862 Share on other sites More sharing options...
gal Posted April 21, 2009 Author Share Posted April 21, 2009 thanks for the link but Ive already tried to use those tutorials to create a form but because my host requires me to add a piece of their code to the scripts for security reasons I can never get the tutorials working. what I would like is for someone to show me how to add an extra field and edit the php to send it in the message. once ive been shown once i can add all the extra fields I need. Ive been trying to figure it out myself but I just cant do it :-s Quote Link to comment https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/#findComment-815941 Share on other sites More sharing options...
AdRock Posted April 21, 2009 Share Posted April 21, 2009 Who does your host think they are dictating what code you can and can't use? I would switch as my host doesn't complain like that. You should be able to use your own code...anyway.. Add in your extra fields as normal and give them a name <FORM method=post action="contact.php"> Forname: <br><INPUT name="first_name" type="text"><br> Surname: <br><INPUT name="last_name" type="text"><br> Email: <br><INPUT name="email" type="text"><br> Message:<br> <TEXTAREA name="message" style="width:500px; height:150px" > </textarea><br> <input type=submit> </FORM> <?php Then add them here mail("info@mysite.co.uk", "Feedback Form results", $_REQUEST['first_name']." ",$_REQUEST['last_name']." ".$_REQUEST['message'], "From: $_REQUEST['email']", "-f".$_REQUEST['email']); header( "Location: index/thankyou.html" ); ?> but you could use something like $message = "Hello $_REQUEST['first_name'] $_REQUEST['last_name'] blah blah blah blah blah blah "; mail("info@mysite.co.uk", "Feedback Form results", $message, "From: $_REQUEST[email]", "-f".$_REQUEST[email]); Quote Link to comment https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/#findComment-815973 Share on other sites More sharing options...
premiso Posted April 21, 2009 Share Posted April 21, 2009 Fixing some minor issues. if (isset($_POST['submit'])) { $message = "FName: {$_POST['first_name']} \n LName: {$_POST['last_name'] \n Message: {$_POST['message']} \n\n"; // the \n indicates a line break. mail("info@mysite.co.uk", "Feedback Form results", $message, "From: {$_POST['email']}", "-f".$_POST['email']); echo "Thank you for submitting a request"; // although a header redirect would be better to prevent double submittals by refresh. }else { echo "No data was submitted."; } It is also better to use the method you expect, so POST or GET as appose to REQUEST. This adds an extra precaution to the data and how it is received. You should know what type of data you expect and where you expect it to come from. As a note, your host has to have a mail server installed for mail to work. Also a minor fix to the form posted: <form method="POST" action="contact.php"> Forname: <br /><input name="first_name" type="text" /><br /> Surname: <br /><input name="last_name" type="text" /><br /> Email: <br /><input name="email" type="text" /><br /> Message:<br /> <textarea name="message" style="width:500px; height:150px" > </textarea><br /> <input name="submit" type="submit" value="Submit" /> </form> Hope that helps out a bit. It is always good to name your input boxes, especially the submit. Quote Link to comment https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/#findComment-816006 Share on other sites More sharing options...
gal Posted April 22, 2009 Author Share Posted April 22, 2009 thanks guys, really appreciate it. I will try this out after work :-) Quote Link to comment https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/#findComment-816207 Share on other sites More sharing options...
premiso Posted April 22, 2009 Share Posted April 22, 2009 I had a syntax error in the revision I did: $message = "FName: {$_POST['first_name']} \n LName: {$_POST['last_name']} \n Message: {$_POST['message']} \n\n"; Replacing that line should fix it. Quote Link to comment https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/#findComment-816333 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.