creating a web contact form in php.

Al.Neri

Super Star
I am trying to create a fully functional php contact form for a website I am making. I don't have any problem making the form itself, but sorting the functioning side of it, the php script is proving more tricky. I don't have any php knowledge, so I am having to start at the bottom and work my way up.

I have searched google for tutorials on the matter, but they are all so long and convoluted that I end up losing where I am up to.

the few that I have found that are within my bracket of expertise, don't seem to work properly.

anyone on here know anything about this, or know of any resources that are easy to follow, but ultimately get the job done?

thanks.
 

Androcles

Rising Star
If you have your own web space and can add php software to it which I assume you can because you want to learn how to make php forms then there's a really simply piece of software you can use on sourceforge, it's calle phpFormGenerator (v2.09) and you can get it from http://phpformgen.sourceforge.net/

If you want to see how it works then I have a demo on my webspace here
 

Al.Neri

Super Star
thanks for the link.

however, I'm trying to learn how to do it myself, so I can build one from scratch. nothing beats knowledge, and ultimately being able to do something yourself. I taught myself html & css, php seems to be the natural progression at this point.
 

Din

Silver Level Poster
Are you trying to get the data sent to a email address or do you want it submitted to a file or a backend area?
 

Androcles

Rising Star
thanks for the link.

however, I'm trying to learn how to do it myself, so I can build one from scratch. nothing beats knowledge, and ultimately being able to do something yourself. I taught myself html & css, php seems to be the natural progression at this point.

Well you could use phpFormGenerator to create the form anf then dissect it and learn from it ;)
 

Tom DWC

Moderator
Moderator
Hey,

There are some pretty decent tutorials out there, the main thing is to make sure they contain some form of spam protection - at the very least a field check. You also want something that checks the fields on the same page without refreshing or moving to another page as there's nothing more annoying than older contact form scripts that clear the contents of every field if there's a mistake.

It's one of those things that once you have a completed script you can reuse it time and time again, in most cases to make changes you just need to restyle the CSS.

If you want a working PHP script with the HTML and CSS so you can have a look at how it works and is pulled together, let me know.
 

Din

Silver Level Poster
for what I'm doing now, to an email address.

So im guessing you have a form along the lines of...

Code:
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

<label for="name">Name:</label>
<input type="text" name="name" id="name" />

<label for="email">Email:</label>
<input type="text" name="email" id="email" />


<label for="message">Message:</label>
<textarea name="message" id="message" textarea>


<input type="submit" name="submit" id="submit" value="Submit"  />
</form>

then you need some code such as:
Code:
<?php
if (isset($_POST['submit']))
{

$name = $_POST['name'];
$message = $_POST['message'];
$email = $_POST['email'];
$yourEmail = '[email protected]';

$to = $yourEmail;
$subject = "New message"
$txt = " Message from:" . $name . ". Message: " . $message;
$headers = "From: " . $email;
 
mail($to, $subject, $txt, $headers); 
}
?>

Theres no validation on that what so eever but it gives you the basic idea
 
Top