website forms

Status
Not open for further replies.

jened

New member
Nov 28, 2006
977
6
0
upstate NY
I want to use forms for users to input data and email me. Not sure what the best way to do this nowadays is. html form and php to process it? I only seem to be finding old stuff or commercial products when i'm searching so if anyone can comment, I'd appreciate it.
 


PHP Contact Form - Google Search

Third result down, just alter the email and teh subject and you should be good to go

PHP:
<?php

// Change these two variables to meet your needs.

$myemail = 'myemail@domain.com';
$subject = 'Contact form Subject';

$op = $_POST[op];

if($op == 'contact')
{
    $name = stripslashes($_POST[name]);
    $email = stripslashes($_POST[email]);
    $text = stripslashes($_POST[text]);
    $referer = $_POST[referer];
    $remote_host = $_SERVER[REMOTE_ADDR];
    $server = $_SERVER[SERVER_NAME];
    $browser = $_SERVER[HTTP_USER_AGENT];

    if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email)) 
    { 
        $status = "We're sorry, but you've entered an incorrect email address.<br>";
    }
    if(!$name)
    {
        $status .= "Please enter your name.<br>";
    }
    if(!$text)
    {
        $status .= "Please enter a message.<br>";
    }

    if(!$status)
    {
        $header = "From: $email\r\nReply-To: $email\r\n";

        $message = "
            Name: $name
            Referer: $referer
            Site: $server
            Remote Host: $remote_host
            Remote Browser: $browser

            $text
        ";

        if(mail($myemail, $subject, $message, $header))
        {
            $status = "Thank you for your Feedback!!<br><br>";
        }
        else
        {
            $status = "There was a problem sending your feedback, please try again later.<br><br>";
        }

    }
    else
    {
        $status .= "<br>Please press <u>back</u> on your browser to resubmit.<br><br>";
    }
}    

// Now check the referer page and ensure it's a proper URL

$referer = $_SERVER[HTTP_REFERER];

if(!preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $referer))
{
    unset($referer);
}

?>

<?php print $status; ?>

<form method="post" action="<?php print $_SELF; ?>">
<input type="hidden" name="op" value="contact">
<input type="hidden" name="referer" value="<?php print $referer; ?>">
Name<br><input name="name" size="35" value=""><br>
E-mail address<br><input name="email" size="35" value=""><br>
<br>Message<br><textarea name="text" cols="50" rows="10"></textarea><br><br>
<input type="submit" value="Send message!">
 
theres a bunch of free and paid services as well that can handle the forms for you. a newsletter or something is great cuz you can later sell what you want to the subscribers. And its good for SEO to make it more relevant and unique and not just a pitch page :)
 
Status
Not open for further replies.