Jump to content

PHP contact form


konetch

Recommended Posts

Hi,

 

I'm still really new to PHP, but I am trying to build a contact form. So far I have

 

<?php
$dontsendemail = 0;
$possiblespam = FALSE;
$strlenmessage = "";
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$subject = "Twitter Backgraphic/Avatar Sale";$emailaddress = "[email protected]";
function checkcaptcha() {
            session_start();
            if ($_SESSION["pass"] != $_POST["userpass"]) {
                die("Sorry, you failed the CAPTCHA. Note that the CAPTCHA is case-sensitive.

Please hit your browser back button and try again.");
                return 1;
            }
        }
    
function checkemail($field) {
    // checks proper syntax
    if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $field))
    {
        die("Improper email address detected. Please hit your browser back button and try again.");
        return 1;
    }
}
function spamcheck($field) {
    if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%

0A",$field)){
        $possiblespam = TRUE;
    }else $possiblespam = FALSE;
    if ($possiblespam) {
        die("Possible spam attempt detected. If this is not the case, please edit the content of the

contact form and try again.");
        return 1;
    }
}
function strlencheck($field,$minlength,$whichfieldresponse) {
    if (strlen($field) < $minlength){
        die($whichfieldresponse);
        return 1;
    }
}

        if ($dontsendemail == 0) $dontsendemail = checkcaptcha($email);
    
if ($dontsendemail == 0) $dontsendemail = checkemail($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($subject);
if ($dontsendemail == 0) $dontsendemail = strlencheck($email,10,"The email address field is too short. Please

hit your browser back button and check your entry.<br>");

if ($dontsendemail == 0) $dontsendemail = strlencheck($message,10,"The message field is too short. Please hit

your browser back button and check your entry.<br>");
if ($dontsendemail == 0) $dontsendemail = strlencheck($emailaddress,8,"You have not selected a recipient of your

message. Please hit your browser back button and check your entry.<br>");
if ($dontsendemail == 0) {mail($emailaddress,"Subject: $subject",$message,"From: $email" ); echo "Thank you for

requesting a TwitBackGraphic. We'll look at your message, and start designing your background.<br><br>Good

Luck!<br>";}
?>

My HTML is

 

<form method="post" id="captcha_form" name="captcha_form" action="mailform.php">

    <div class="over">Name: <br><input type="text" size="30" name="name id="name" value="">
    </div>
<div class="over">Twitter name @twitter.com(username) <br><input type="text" size="30" name="twitter"

id="twitter" value="">
    </div>
<div class="over">Email address: <br><input type="text" size="30" name="email" id="email" value="">
    </div>
<?php $subject = "Twitter Backgraphic/Avatar Sale"; ?>
    <div class="over">How would you like your design? Submit all information you want included in your

twitbackgraphic<br><span style="font-size:10px;">(Colors, style, twitter name, and other information you want in

your design)</span>
                    <br><textarea name="message" id="message" rows="10" cols="60"><?php echo

"</tex" . "tarea>"; ?>
                        <br>
    </div>
<div class="over">
                    <img src="captcha.php" alt="Captcha">  <span style="font-

size:10px;">Note: CaSE sEnsITivE</span>
                    <br><input type="text" name="userpass" value="">
    </div>
    <div style="padding-bottom: 1em;"><input name="submit" type="submit" value="Submit">
    </div>
</form>

Could you show me how to make the name and twitter fields show up in the email message.

 

Thanks for the help

 

Alex

Link to comment
https://forums.phpfreaks.com/topic/162782-php-contact-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.