[?] Whats wrong with this php form :'(

Discussion in 'Programming' started by Kajs@, Oct 3, 2009.

  1. #1
    this is my contact form. but when i click send an ERROR happen :(

    index.php source:
    
    <form action="mail.php" method="post">
    name <input type="text" name="name" size="40">
    family <input type="text" name="family" size="40">
    phone <input type="text" name="phone" size="40">
    address <input type="text" name="address" size="40">
    <input type="submit" value="send">
    </form>
    
    Code (markup):
    mail.php source:
    
    <?php
    $to="info@example.tld";
    $subject="feedback";
    $from="visitor@example.tld";
    $name=$_POST['name'];
    $family=$_POST['family'];
    $phone=$_POST['phone'];
    $address=$_POST['address'];
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'To: '.$to . "\r\n";
    $headers .= 'From: '.$from . "\r\n";
    $headers .= 'Reply-To: '.$from . "\r\n";
    $sendmail=mail($to, $subject, $name, $family, $phone, $address, $headers);
    if ($sendmail)
    echo "sent";
    else
    echo "failed";
    ?>
    
    Code (markup):
    please correct it and place here. thank you very much
     
    Kajs@, Oct 3, 2009 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    
    <?php
    
    $to='info@example.tld';
    $subject='feedback';
    $from='visitor@example.tld';
    
    // NOTE: You should validate all data coming from forms -
    // ESPECIALLY IN EMAIL FORMS!
    $name=$_POST['name'];
    $family=$_POST['family'];
    $phone=$_POST['phone'];
    $address=$_POST['address'];
    
    $message = "Name: $name\nFamily: $family\nPhone: $phone\nAddress: $address";
    
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: '.$from . "\r\n";
    $headers .= 'Reply-To: '.$from . "\r\n";
    
    // bool mail( string $to  , string $subject  , string $message  , string $additional_headers)
    $sendmail=mail($to, $subject, $message, $headers);
    if ($sendmail)
    echo "sent";
    else
    echo "failed";
    ?>
    
    Code (markup):
     
    rainborick, Oct 3, 2009 IP