How to make my contact form work?

Discussion in 'Web Design and Development' started by Boots-, Jul 10, 2009.

  1. Boots- macrumors regular

    Joined:
    Jan 27, 2009
    Location:
    Canada
    #1
    I'm working on a website, it's not quite finished yet, but it is in the works. I'm trying to get my contact form to work. Here is the code I have:


    <?php
    $contact_name = $_POST['name'];
    $contact_email = $_POST['email'];
    $contact_subject = $_POST['subject'];
    $contact_message = $_POST['message'];

    if( $contact_name == true )
    {
    $sender = $contact_email;
    $receiver = "MyEmailHere";
    $client_ip = $_SERVER['REMOTE_ADDR'];
    $email_body = "Name: $contact_name \nEmail: $sender \n\nSubject: $contact_subject \n\nMessage: \n\n$contact_message \n\nIP: $client_ip \n\nFlash Contact Form provided by http://www.flashmo.com";
    $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

    if( mail( $receiver, "Flash Contact Form - $contact_subject", $email_body, $extra ) )
    {
    echo "success=yes";
    }
    else
    {
    echo "success=no";
    }
    }
    ?>







    It doesn't seem to work when I try it out, What do I have to do to make it work? (besides adding my email where it says EmailHere)
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Short answer, your if statement. You should check that it's not empty,
    PHP:
    if ($contact_name != '') {
    There's a number of security issues though. Your form can easily be turned into a spam machine. You must validate the data being submitted through the form, otherwise it'll be a prime candidate for email-injection attacks.

    Side note; When posting code be sure to use the appropriate code tags i.e., use the PHP button around your code. This will properly format and color code the code you post like you see above.
     
  3. Boots- thread starter macrumors regular

    Joined:
    Jan 27, 2009
    Location:
    Canada
    #3
    What can I do to make it work, and make it not a spam machine?
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Read the link I gave. You didn't say if you tried the revised if statement I suggested, and you haven't said in what way it isn't working. Are there errors, is there any output? We also don't know what your form looks like.
     
  5. Boots- thread starter macrumors regular

    Joined:
    Jan 27, 2009
    Location:
    Canada
    #5
  6. Boots- thread starter macrumors regular

    Joined:
    Jan 27, 2009
    Location:
    Canada
    #6
    I just found out that Bravenet does not support PHP with a free account, what is a good, free webhost to use?
     

Share This Page