[Please Help] Collecting data.

bornformoney

Supreme Member
Joined
Feb 22, 2011
Messages
1,209
Reaction score
1,683
So, I am trying to collect data using an html form, but after the user clicks "submit", I want it to either appear in my email or have it on my server.

I think it's the PHP 'get' function, but not too sure about it.

Can anybody help me out or have an example I can use? Thanks.
 
For example, if you have this form:
Code:
<form action="post.php" method="post">
	First name:<input type="text" name="firstname"/>
	Last name:<input type="text" name="lastname" />
	E-mail:<input type="text" name="email" />
	<input type="submit" value="Submit" />
</form>

When the user submits his info, the varibles firstname, lastname, email are sent using POST requests to the post.php script.
In post.php you can have:
Code:
$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "New whatever";
$FirstName = Trim(stripslashes($_POST['firstname'])); 
$LastName = Trim(stripslashes($_POST['lastname']));
$NewUserEmail = Trim(stripslashes($_POST['email']));
$Body = "New user: ".$FirstName." ".$LastName." with email ".$NewUserEmail;

then you use the mail function to send a new email to your email address:
Code:
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.yourwebsite.com\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}

Hope this makes sense to you.
 
Back
Top