Jump to content

Recommended Posts

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" );

?>

Link to comment
https://forums.phpfreaks.com/topic/155090-simple-form-to-mail-help/
Share on other sites

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

 

 

 

 

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]);

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.