how to write a contact form

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

zombienation

Thread Starter
Joined
Aug 6, 2003
Messages
337
Hi There I have written a webpage with home, about etc + a contact page

Now I have written a form for the contact button how can i Direct it to go to my email after i press the submit button

hopefully somebody can help me out.
 

Attachments

Joined
Aug 12, 2007
Messages
696
Lots of ways to do this on your own, but I have used formmail.php (available here) with success in the past.
 
Joined
Nov 28, 2011
Messages
2
One possibility is to use two separate files:

contact.html

Include this form somewhere in your HTML code.
HTML:
<form method="post" action="mailer.php">
Name:<br/>
<input type="text" name="name" /><br/>
Subject:<br/>
<input type="text" name="subject" /><br/>
E-Mail:<br/>
<input type="text" name="email" /><br/>
Website:<br/>
<input type="text" name="website" /><br/>
Message:<br/>
<textarea id="message" cols="35" rows="5"></textarea><br/>
<input type="submit" value="Submit!" />
</form>
mailer.php

Put this file in the same folder as the contact page.
PHP:
// get variables from the post
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$website = $_POST['website'];
$message = $_POST['message'];
 
// Your email here
$to = "[email protected]";
 
// The actual mailer function 
mail($to,$subject,$message);
This is just a simple form with a POST method. The php then grabs the HTML form data and puts them into the php mail function. If you want to, you should also add some sort of CAPTCHA to prevent from bots/spam entering your email.
 
Joined
Aug 12, 2007
Messages
696
One possibility is to use two separate files:
Why 2 separate files? It's much easier from a maintenance standpoint to have all of this in a single file, then have the form page post to itself. After processing, the php code can redirect to another page (e.g., "Thanks for your submission") or flag fields on the form for further information gathering.
 
Joined
Nov 28, 2011
Messages
2
Well yes of course, I simply used two files to point out the way forms work...

contact.php:

(instead of contact.php, you can use <?php echo $_SERVER['PHP_SELF']; ?>)
PHP:
<?php
if(isset($_POST['submit'])){ 
// get variables from the post
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$website = $_POST['website'];
$message = $_POST['message'];
 
// Your email here
$to = "[email protected]";
 
// The actual mailer function 
mail($to,$subject,$message);  
}
?>

<form method="post" action="contact.php">
Name:<br/>
<input type="text" name="name" /><br/>
Subject:<br/>
<input type="text" name="subject" /><br/>
E-Mail:<br/>
<input type="text" name="email" /><br/>
Website:<br/>
<input type="text" name="website" /><br/>
Message:<br/>
<textarea id="message" cols="35" rows="5"></textarea><br/>
<input type='hidden' name='submit' />
<input type="submit" value="Submit!" />
</form>
That should do the trick.
 
Joined
Feb 7, 2011
Messages
186
Hi There I have written a webpage with home, about etc + a contact page

Now I have written a form for the contact button how can i Direct it to go to my email after i press the submit button

hopefully somebody can help me out.

Hey idk if you solved this already but I've been playing with google forms and kinda love the simplicity and easy email notification. Here's a simple tut on how to setup a form to dump to a spreadsheet and notify you via email of new entries.

http://youtu.be/E5CfuRTy1V4

just my .2
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top