Posting Name In Email Form?

Discussion in 'PHP' started by gobbly2100, Sep 10, 2007.

  1. #1
    Hey,

    I have this script I found and I am now using but the box where people enter their name seems pointless as I don't actually see their name in the email I receive.

    <?php
    if($_POST['do']=="send") {
    $recipient="email"; // Set your email here //
    $subject=$_POST['subject'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $message=$_POST['message'];
    $formsend=mail("$recipient", "$subject", "$message", "From: $name ($email)\r\nReply-to:$email");
    echo("<p>Your message was successfully sent!</p>");
    }
    ?>
    Code (markup):
    How can I actually get the name of the person who tried to contact me?
     
    gobbly2100, Sep 10, 2007 IP
  2. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Make sure the input field for the name has name="name" on it somewhere.
     
    Synchronium, Sep 10, 2007 IP
  3. gobbly2100

    gobbly2100 Banned

    Messages:
    906
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well I don't really know much about PHP, I just copied the script, maye you could check the HTML code?

    
    <form method="post" action="">
    <p>Name:<br>
    <input name="name" type="text" />
     </p>
    <p>Email:<br>
    <input name="email" type="text" />
     </p>
    <p>Subject:<br>
    <input name="subject" type="text" />
     </p>
    <p>Message:<br>
    <textarea name="message" rows="6"></textarea>
     <br />
    <input type="submit" value="Send" /><input type="hidden" name="do" value="send" /><input type="reset" value="Reset" />
     </p></form>
    
    Code (markup):
    Thanks for your help!
     
    gobbly2100, Sep 10, 2007 IP
  4. stats

    stats Well-Known Member

    Messages:
    586
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #4
    what i would suggest to do is the following


    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: $name <$email>' . "\r\n";
    
    mail("$recipient", "$subject", "$message", $headers)
    PHP:
    (source - http://www.php.net/manual/en/function.mail.php)
     
    stats, Sep 11, 2007 IP