Help with a simple form to email script

Discussion in 'PHP' started by madmn, Nov 27, 2009.

  1. #1
    I need some Help with a simple form to email script.

    Here is the code:

    <?php
    if(!isset($_POST['submit']))
    {
    //This page should not be accessed directly. Need to submit the form.
    echo "error; you need to submit the form!";
    }
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];
    $found = $_POST['found'];

    //Validate first
    if(empty($name)||empty($visitor_email))
    {
    echo "Name and email are mandatory!";
    exit;
    }

    if(IsInjected($visitor_email))
    {
    echo "Bad email value!";
    exit;
    }

    $email_from = 'Email Address';//<== update the email address
    $email_subject = "New Form submission";
    $email_body = "You have received a new message from the user $name.\n".
    "Here is the message:\n $message\n".
    "They found us from : $found";

    $to = "Email Address";//<== update the email address
    $headers = "From: $email_from \r\n";
    $headers .= "Reply-To: $visitor_email \r\n";
    //Send the email!
    mail($to,$email_subject,$email_body,$headers);
    //done. redirect to thank-you page.
    header('Location: thank-you.html');


    // Function to validate against any email injection attempts
    function IsInjected($str)
    {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    ?>


    All I did was add more fields and I am wondering if they will work right. Any help would be appreciated.
     
    madmn, Nov 27, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Do you mean more email fields?
     
    s_ruben, Dec 1, 2009 IP
  3. RaulG

    RaulG Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Help offered 100U$S
     
    RaulG, Dec 1, 2009 IP
  4. zoneweb

    zoneweb Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can add as many as you want.
     
    zoneweb, Dec 1, 2009 IP