Results 1 to 5 of 5

Thread: PHP form need required fields and anti spam security

  1. #1
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP form need required fields and anti spam security

    Hi I have created a form that I want results sent to my email but i want it to have required fields and make the form secure from spam. My php looks like this: Can someone help me make the fields required and secure from spam please?

    Thanx


    [PHP
    <?php

    $result = "Beechwood Homes website enquiry form\r\n\r\n";
    $result .= "Developments: " . $Developments . "\r\n";
    $result .= "Name: " . $Fname . "\r\n";
    $result .= "Last Name: " . $Lname . "\r\n";
    $result .= "Email: " . $Email . "\r\n";
    $result .= "Tel: " . $Phone . "\r\n";
    $result .= "Address: " . $Address . "\r\n";
    $result .= "Address2: " . $Address2 . "\r\n";
    $result .= "Town: " . $Town . "\r\n";
    $result .= "County: " . $County . "\r\n";
    $result .= "Postcode: " . $Postcode . "\r\n";
    $result .= "Country: " . $Country . "\r\n";
    $result .= "Min property price: " . $Minprice . "\r\n";
    $result .= "Max property price: " . $Maxprice . "\r\n";
    $result .= "Do you have a house to sell?: " . $Selling . "\r\n";
    $result .= "How did you find this Web Site?: " . $Source . "\r\n";
    $result .= "Please tick the box if you would like to be added to our mailing list: " . $Mailinglist . "\r\n";


    if ($Email) {
    $headers = "From: $Fname <$Email>\r\n\r\n";
    } else {
    $headers = "From: No Name given <anonymous@yourserver.com>\r\n\r\n";
    }

    $sendit = mail("my@email.co.uk", "Website contact form", $result, $headers) or die("Something went wrong");

    echo "<meta http-equiv='refresh' content='0; url=thank.htm'>";
    die;

    ?>
    ][/PHP]

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can validate your form fields using JavaScript and PHP (the PHP part is optional) before sending the mail.

    The following page will give you a step by step explanation about various mail sending methods in PHP using the normal mode:

    http://www.webcheatsheet.com/PHP/sen...attachment.php

    PEAR PHP extension supports a mail class which contains various utilities and you can make use of that if you need that:

    http://www.hudzilla.org/phpbook/read.php/15_5_2

    For me when I've used the mail function of PHP sometimes it acted as spams and when I used the PEAR it worked for me.

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    i think you mean the other way around. the javascript is optional. php is mandatory. people could bypass the javascript by disabling it.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Master Script Maker is right: if validation is necessary, use javascript to make it easier but do not rely on that javascript.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by shush1 View Post
    PHP Code:
    $sendit mail("my@email.co.uk""Website contact form"$result$headers) or die("Something went wrong");

    echo 
    "<meta http-equiv='refresh' content='0; url=thank.htm'>";
    die;

    ?> 
    get rid of the html redirect, instead use
    PHP Code:
    if(mail("my@email.co.uk""Website contact form"$result$headers))
    {
         
    // sends the user to the good page
         
    header('thank.htm');
    }
    else
    {
         
    // kills the processing and prints an error
         
    die('Could not send email');

    Last edited by boogyman; 03-14-2008 at 03:22 PM. Reason: added comment

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •