[SOLVED] Contact Form Help

This is a discussion on "[SOLVED] Contact Form Help" within the PHP Forum section. This forum, and the thread "[SOLVED] Contact Form Help are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 7th, 2007, 13:06
Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Contact Form Help

Hey. How on earth do i make a contact form with this code........ im useless with php but i HAVE to use this code for a contact form i really dont know where to start.

Code: Select all
<?
function antispam()
{
// First, make sure the form was posted from a browser.
// For basic web-forms, we don't care about anything
// other than requests from a browser:
    if (!isset($_SERVER['HTTP_USER_AGENT'])) {
        die("Forbidden - You are not authorized to view this page");
        exit;
    }
// Make sure the form was indeed POST'ed:
    //  (requires your html form to use: action="post")
    if (!$_SERVER['REQUEST_METHOD'] == "POST") {
        die("Forbidden - You are not authorized to view this page");
        exit;
    }
// Make sure the form was posted from an approved host name.
    if (!strstr($_SERVER['HTTP_REFERER'], "cashincar")) {
        //logBadRequest();
        header("HTTP/1.0 403 Forbidden");
        exit;
    }
// Attempt to defend against header injections:
    $badStrings = array("Content-Type:",
    "MIME-Version:",
    "Content-Transfer-Encoding:",
    "bcc:",
    "cc:",
    "http://"    );
// Loop through each POST'ed value and test if it contains
    // one of the $badStrings:
    foreach($_POST as $k => $v){
        foreach($badStrings as $v2){
            if (strpos($v, $v2) !== false) {
                //        logBadRequest();
                header("HTTP/1.0 403 Forbidden");
                exit;
            }
        }
        
    }
    
}
// do stuff to the post
if ($_POST) {
antispam();
while (list($key, $value) = each($_POST)) {
$$key = $value;
$message .=$key.": ".$value."\n";
}
//mail form    
$message = "There has been a message/request from ".$_SERVER['HTTP_HOST']."\n\n".$message;
$message .="-----------------------\n\n";
$message = stripslashes($message);
mail("web@geneticsltd.co.uk", "Genetics Feedback", $message, "From: web@geneticsltd.co.uk");
} 
?>

Last edited by karinne; Nov 7th, 2007 at 14:42. Reason: Change the [ quote ] to [ code ] to display code
Reply With Quote

  #2 (permalink)  
Old Nov 7th, 2007, 13:54
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 22
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Lucleonhart Send a message via MSN to Lucleonhart
Re: Contact Form Help

Well, the Script dynamically tests all POSTed content for illegal characters.. so you can do whatever you want in your contact form. Save the code you posted as "check.php" and take this as an example:
HTML: Select all
<html>
<head>
<title>My Contact Form</title>
</head>
<body>
<form name="contact" action="check.php" method="POST">
Your name: <input type="text" name="name" /><br />
Your email: <input type="text" name="email" /><br />
Your Message: <textarea name="message"></textarea><br />
<input type="submit" value="Send" />
</form>
</body>
</html>
This will send all Form Elements to the check.php. If everything is all right, the script sends a message to "web@geneticsltd.co.uk" With the subject "Genetics Feedback" and the Message

"There has been a message/request from <yourhostname>
name: <insertedname>
email: <insertedemail>
message: <insertedmessage>"
Reply With Quote
  #3 (permalink)  
Old Nov 7th, 2007, 14:27
Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Contact Form Help

Thankyou lucleonhart, this is a big help
Reply With Quote
  #4 (permalink)  
Old Nov 7th, 2007, 16:05
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,639
Thanks: 0
Thanked 7 Times in 7 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: Contact Form Help

Since the thread is solved, do you mind marking it as solved?

Thread Tools -> Mark Thread as Solved.
Reply With Quote
Reply

Thread Tools

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP contact form problem fl0w PHP Forum 12 Jan 31st, 2008 17:56
[SOLVED] PHP contact form redirect to same form Posie PHP Forum 14 Jan 29th, 2008 20:28
[SOLVED] Wordpress contact form - getting 404 on send Aso PHP Forum 3 Jan 25th, 2008 11:23
[SOLVED] PHP Contact Form Stuart PHP Forum 8 Dec 4th, 2007 17:42
[SOLVED] PHP Contact Form Stuart PHP Forum 9 Oct 20th, 2007 00:48


All times are GMT. The time now is 22:00.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43