Go Back   Random Stuff Forums > Technical > Programming

Programming Discuss any type of programming here.

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 14-07-2009, 08:39 PM
Matt's Avatar
(Offline)
Administrator
 
Join Date: Jan 2007
Location: United States - Ohio
Posts: 3,820
Matt is an unknown quantity at this point
Default [PHP][HTML] Simple Contact Form

Here is how to make a simple contact form with an HTML form and a simple PHP file to handle it.

This is the HTML code for a VERY basic form. This can be manipulated very easily to fit with styling etc, the only parts that must be kept in tact are the form and its elements.
<html>
<head>
</head>
<body>
<table>
<form name="main" method="post" action="contact.php">
<tr><td>Subject:&nbsp;</td><td><input name="subject" type="text" id="subject" size="50"></td></tr>
<tr><td>Name:&nbsp;</td><td><input name="name" type="text" id="name" size="50"></td></tr>
<tr><td>Email:&nbsp;</td><td><input name="email" type="text" id="email" size="50"></td></tr>
<tr><td>Message:&nbsp;</td><td><textarea name="message" cols="50" rows="4" id="message"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit"></td></tr>
</form>
</body>
</html>
Here is the PHP component. (This would go in a file called "contact.php" because that was the "action" property specified in the HTML form)
<?php

// Get the email from the form
$email_from = $_POST['email'];

//Get the name from the form
$name = $_POST['name'];

// Get the subject from the form
$subject = $_POST['subject'];

// Get the message from the form
$message = $_POST['message'];

//Check if any fields were left blank...
if ($message == "" || $subject == "" || $name == "" || $email_from == "") {
echo 'You left one or more field blank.  Please go back and fix this.';
}
else {
//Combine $name $email_from and $message
$body  =  "From: $name\n E-Mail: $email_from\n Message:\n $message";

// The email address to send the info. to
$to = 'your@email.com';

//Send the email
$sendEmail = mail($to, $subject, $body);
echo 'Your message was sent.  Thank you!';
}
?>

Please note that this can be made more complex, but this is just a very simple, bare bones contact form in this thread.
__________________
"Facts do not cease to exist because they are ignored."

Last edited by Matt; 15-07-2009 at 08:57 AM..
Reply With Quote
  #2  
Old 14-07-2009, 08:40 PM
World Domination's Avatar
(Offline)
Super Sexy Admin
 
Join Date: Jan 2007
Location: Illinois, USA
Posts: 7,384
World Domination is an unknown quantity at this point
Default

Ah thanks for this Matt.I'm actually going to use it. It saves me from writing up my own (or wasting time online finding one that doesn't even work).
Thanks.
__________________
RSForums.org - We Don't give a fuck.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

"It's not yelling, it's projecting; and by the way, my voice is soothing."
-Billy Mays

Reply With Quote
  #3  
Old 15-07-2009, 05:01 AM
World Domination's Avatar
(Offline)
Super Sexy Admin
 
Join Date: Jan 2007
Location: Illinois, USA
Posts: 7,384
World Domination is an unknown quantity at this point
Default

Originally Posted by Matt View Post
<html>
<head>
</head>
<body>
</body>
<table>
<form name="main" method="post" action="contact.php">
<tr><td>Subject:&nbsp;</td><td><input name="subject" type="text" id="subject" size="50"></td></tr>
<tr><td>Name:&nbsp;</td><td><input name="name" type="text" id="name" size="50"></td></tr>
<tr><td>Email:&nbsp;</td><td><input name="email" type="text" id="email" size="50"></td></tr>
<tr><td>Message:&nbsp;</td><td><textarea name="message" cols="50" rows="4" id="message"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit"></td></tr>
</form>
</html>
I just now looked at this and you have your </body> tag in the wrong spot. It should be under the last </form> tag.
__________________
RSForums.org - We Don't give a fuck.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

"It's not yelling, it's projecting; and by the way, my voice is soothing."
-Billy Mays

Reply With Quote
  #4  
Old 15-07-2009, 06:00 AM
Chase's Avatar
(Offline)
RSF Regular
 
Join Date: Mar 2007
Location: Australia
Posts: 2,483
Chase is an unknown quantity at this point
Default

OMFG DOUBLE POST MERGE IT OMG OMG OMG OMG
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Reply With Quote
  #5  
Old 15-07-2009, 08:58 AM
Matt's Avatar
(Offline)
Administrator
 
Join Date: Jan 2007
Location: United States - Ohio
Posts: 3,820
Matt is an unknown quantity at this point
Default

Originally Posted by World Domination View Post
I just now looked at this and you have your </body> tag in the wrong spot. It should be under the last </form> tag.
Yeah, my bad. I just threw an HTML file together there really quickly and must have overlooked it. Thanks for letting me know
__________________
"Facts do not cease to exist because they are ignored."
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 04:07 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright © 2006 - 2010, Rsforums.org