Grow your CSS skills. Land your dream job.

[Continue] Contact form

  • # November 28, 2009 at 9:44 am

    Hey,

    I dont understand PHP very much, so i used a script to make a contact form on my website. There’s a secure code, but if you just enter the code, you are able to send a blank message. If someone know what i can put into my "mailer.php" so you have to enter something in all the fields, it would be nice. You can find it here: http://www.graphicaldesign.wep.dk/kontakt.html
    It’s danish, but i hope someone can help. If you want the code from mailer.php just tell me.

    Greetings,
    Dev



    It has been continued. Read my latest post.

    # November 28, 2009 at 1:36 pm

    What script did you use to create this contact form?
    Did you just get some HTML code from somewhere?

    # November 28, 2009 at 2:44 pm

    I searched for a script. It used PHP. Here’s the code if it helps:

    Mailer.php

    Code:
    < ?php
    // -----------------------------------------
    // The Web Help .com
    // -----------------------------------------
    // remember to replace you@email.com with your own email address lower in this code.

    // load the variables form address bar
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $from = $_POST["from"];
    $verif_box = $_POST["verif_box"];

    // remove the backslashes that normally appears when entering " or '
    $message = stripslashes($message);
    $subject = stripslashes($subject);
    $from = stripslashes($from);

    // check to see if verificaton code was correct
    if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
    // if verification code was correct send the message and show this page
    mail("chr.bundgaard@hotmail.com", '(GD) '.$subject, $_SERVER['REMOTE_ADDR']."nn".$message, "From: $from");
    // delete the cookie so it cannot sent again by refreshing this page
    setcookie('tntcon','');
    } else if(isset($message) and $message!=""){
    // if verification code was incorrect then return to contact page and show error
    header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
    exit;
    } else {
    echo "Den indtastede sikkerhedskode var forkert. Gå tilbage og prøv igen.";
    exit;
    }
    ?>
    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



    Beskeden er sendt, tak for din henvendelse.

    Gå tilbage til forsiden?

    HTML

    Code:

    E-mail:

    Klik her og få en ny.


    < ?php if(isset($_GET['wrong_code'])){?>

    Forkert sikkerhedskode


    < ?php ;}?>

    Besked:



    # November 28, 2009 at 3:09 pm

    Here';s the updated PHP code to check to make sure that the Subject, message and From fields all have at least one character in them… I didn’t make any sort of error coding, All errors will lead to the same page:

    For now you can just update the page to say "or you didn’t fill in a field…"

    It’s a simple start.

    Code:
    < ?php
    // -----------------------------------------
    // The Web Help .com
    // -----------------------------------------
    // remember to replace you@email.com with your own email address lower in this code.

    // load the variables form address bar
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $from = $_POST["from"];
    $verif_box = $_POST["verif_box"];

    // remove the backslashes that normally appears when entering " or '
    $message = stripslashes($message);
    $subject = stripslashes($subject);
    $from = stripslashes($from);

    // check to see if verificaton code was correct
    if(md5($verif_box).'a4xn' == $_COOKIE['tntcon'] && strlen($message) > 0 && strlen($subject) > 0 && strlen($from ) > 0 ){
    // if verification code was correct (and fields validate), send the message and show this page
    mail(“chr.bundgaard@hotmail.com”, ‘(GD) ‘.$subject, $_SERVER['REMOTE_ADDR'].”nn”.$message, “From: $from”);
    // delete the cookie so it cannot sent again by refreshing this page
    setcookie(‘tntcon’,”);
    } else if(isset($message) and $message!=””){
    // if verification code was incorrect then return to contact page and show error
    header(“Location:”.$_SERVER['HTTP_REFERER'].”?subject=$subject&from=$from&message=$message&wrong_code=true”);
    exit;
    } else {
    echo “Den indtastede sikkerhedskode var forkert. Gå tilbage og prøv igen.”;
    exit;
    }
    ?>
    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



    Beskeden er sendt, tak for din henvendelse.

    Gå tilbage til forsiden?

    # November 29, 2009 at 8:07 am

    Thank you, it works. But there’s one problem. If you fill out every field, and it succes’s to sent, this shows up over my "You’ve sent it"-message:

    Warning: Cannot modify header information – headers already sent by (output started at F:HJEMMESIDERGRAPHICALDESIGNGRAPHICALDESIGN.WEP.DKmailer.php:1) in F:HJEMMESIDERGRAPHICALDESIGNGRAPHICALDESIGN.WEP.DKmailer.php on line 23

    Do you know what’s wrong?

    # November 29, 2009 at 1:20 pm

    Take out all spaces before the <?

    # November 30, 2009 at 8:01 am

    Thanks again – it works perfectly now :)

    # November 30, 2009 at 11:11 am

    Excellent! [img]http://www.websitesinaflash.com/images/thumbsup.gif[/img]

    # December 10, 2009 at 12:59 pm

    Hey again. I’m using the same script for a new website – for a friend. Do you know how to add "categories", så you can choose between somthing different things. Here’s an example:

    Booking (send mail to booking@domain.com)
    Webmaster (send mail to webmaster@domain.com)
    Questions (send mail to support@domain.com)

    Or something like that…

    # December 13, 2009 at 10:44 pm

    It’s not a simple answer, but I can start you in the right direction:

    You create a <select name="category"> element with the three different categories as different <options>.
    Make the value for each option ="theemail@address" for that option.

    Then change the mail function:

    Code:
    mail(“chr.bundgaard@hotmail.com”, ‘(GD) ‘.$subject, $_SERVER['REMOTE_ADDR'].”nn”.$message, “From: $from”);

    To:

    Code:
    mail(“$_POST['category']“, ‘(GD) ‘.$subject, $_SERVER['REMOTE_ADDR'].”nn”.$message, “From: $from”);

    I would also recommending programming a validation for that field too, to make sure it is correct.

    # December 14, 2009 at 7:49 am

    Sounds nice – i’ll try. But what do you mean with a validation for that field?

    Edit:

    The HTML works, but when i want to send the message i get this error:

    Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in F:HJEMMESIDERGRAPHICALDESIGNTEST.WEP.DKmailer.php on line 21

    My css line 21 is:

    Code:
    mail(“$_POST['category']“, ‘(GD)’.$subject, $_SERVER['REMOTE_ADDR'].”nn”.$message, “From: $from”);
    # December 14, 2009 at 11:59 am

    Let me see your HTML <select….>

    # December 14, 2009 at 12:28 pm

    Here – i just tried, i’ve no experience in forms/PHP:

    Code:
    Kategori:

    # December 14, 2009 at 12:29 pm

    Replace:
    </select name>
    with:
    </select>

    Try that.

    oh, and take the quotes off of the $_Post:

    mail("$_POST",
    Should be:
    mail($_POST,

    # December 14, 2009 at 12:35 pm

    Hmm… I can’t count how many times you’ve helped me with success – THANKS again! :)

    The error aint appearing anymore – now i just have to be sure that i get the message :)

Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".