"Contact Us" Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • popnbrown
    New Member
    • Oct 2006
    • 24

    #1

    "Contact Us" Form

    Anyone know how to write PHP that can take values that a user inputs into a form on a webiste and the e-mail those values to myself. In other words how do i write PHP code for a Contact Us Form?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    What is your game here? You had the same question answered in the HTML forum http://www.thescripts.com/forum/thread578591.html and you were shown (by me) a PHP script that does exactly that! After that post there has been a full discussion in the HTML forum.

    You are DOUBLE POSTING!
    What is the reason you post the same question here?? Look at the mentioned reply-post and use it.

    When you have a problem with it, state your problem, but don't start another new discussion!

    Ronald :cool:

    Comment

    • popnbrown
      New Member
      • Oct 2006
      • 24

      #3
      the ones posted there do not work, and ppl told me to move it to the PHP section, so I did. Also I'm trying to figure out but no one has posted anything for the past 3 days. My problem right now is really only about the PHP part, yet another reason why I started a new discussion.

      So sorry if i made you mad, I didnt mean to its just that I need to get this done ASAP and I need some help.

      Comment

      • frazzle
        New Member
        • Dec 2006
        • 7

        #4
        Here is how I have done it.

        First the form code:

        [php]
        <form action="email.p hp" method="post">
        Name<br><input type="text" name="username" size="50">
        <p style="text-align: center; font-family:arial, verdana, lucida, helvetica, sans-serif;font-size: 16px">
        Email Address<br><inp ut type="text" name="useraddr" size="50">
        <p style="text-align: center; font-family:arial, verdana, lucida, helvetica, sans-serif;font-size: 16px">
        Comment<br>
        <textarea name="comments" cols="50" rows="20"></textarea><br>
        <input type="submit" value="Send Comment">
        </form>
        [/php]

        And then the code that is executed when you click on "Send Comment":

        [php]
        <?php

        $comments = $_POST['comments'];
        $username = $_POST['username'];
        $useraddr = $_POST['useraddr'];

        $to = "destination@do main.com";
        $re = "Website Comment Form";
        $msg = $comments;
        $headers = 'From: ' . $username . ' <' . $useraddr . '>' . "\r\n" .
        'Reply-To: ' . $username . ' <' . $useraddr . '>' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

        mail( $to,$re,$msg,$h eaders );

        ?>

        <html>
        <head><title>Me sssage Received</title></head>
        <body>
        <center><h3 class=h16>Thank You For Your Comments</h3></center>
        <p>
        <center>Messa ge received from <?php echo( $username ); ?>
        <br>
        Reply to <?php echo( $useraddr ); ?></center>
        </body>
        </html>
        [/php]

        This is very basic but has worked for me. I need to beef it up with Captcha so bots can't exploit it

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Would I be wrong to assume you'd need an active mail service on you server to use the main() function?

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            What do you mean by "an active mail service"? You can install your own mail server or use an existing one. The latter is usually used. Only requirement is that your ISP allows you to send out mail (usually via port 25).

            Ronald :cool:

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Yea thats what I thought,
              not really sure wtf I was thinking when I wrote that :-P

              Comment

              • popnbrown
                New Member
                • Oct 2006
                • 24

                #8
                Originally posted by frazzle
                Here is how I have done it.

                First the form code:

                [php]
                <form action="email.p hp" method="post">
                Name<br><input type="text" name="username" size="50">
                <p style="text-align: center; font-family:arial, verdana, lucida, helvetica, sans-serif;font-size: 16px">
                Email Address<br><inp ut type="text" name="useraddr" size="50">
                <p style="text-align: center; font-family:arial, verdana, lucida, helvetica, sans-serif;font-size: 16px">
                Comment<br>
                <textarea name="comments" cols="50" rows="20"></textarea><br>
                <input type="submit" value="Send Comment">
                </form>
                [/php]

                And then the code that is executed when you click on "Send Comment":

                [php]
                <?php

                $comments = $_POST['comments'];
                $username = $_POST['username'];
                $useraddr = $_POST['useraddr'];

                $to = "destination@do main.com";
                $re = "Website Comment Form";
                $msg = $comments;
                $headers = 'From: ' . $username . ' <' . $useraddr . '>' . "\r\n" .
                'Reply-To: ' . $username . ' <' . $useraddr . '>' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();

                mail( $to,$re,$msg,$h eaders );

                ?>

                <html>
                <head><title>Me sssage Received</title></head>
                <body>
                <center><h3 class=h16>Thank You For Your Comments</h3></center>
                <p>
                <center>Messa ge received from <?php echo( $username ); ?>
                <br>
                Reply to <?php echo( $useraddr ); ?></center>
                </body>
                </html>
                [/php]

                This is very basic but has worked for me. I need to beef it up with Captcha so bots can't exploit it
                So I make this two different pages. One for the form and the other is with Message Recieved page?

                Comment

                Working...