Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bouzy
    New Member
    • Jun 2007
    • 30

    Forms

    Hello I am having a problem with forms. I know they are easy for some people, but I am new. I am trying to make a simple feedback form. Hear is what I have so far...
    [code=php]
    <?php

    //process the email
    if (array_key_exis ts('send', $_POST)) {
    $to = 'goldfishgraphi cs@gmail.com'; //use your own email
    $subject = 'Project Idea';

    //process the $_POST variables
    $name = $_POST['name'];
    $email = $_POST['comments'];

    //build the message
    $message = "Name: $name\n\n";
    $message .= "Email: $email\n\n";
    $message .= "Project Idea: $comments";

    //limit line length to 55 characters
    $message = wordwrap($messa ge, 55);

    //send it
    $mailSent = mail($to, $subject, $message);
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtmll/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

    <title>Goldfi sh Graphics</title>

    <link type="text/css" rel="stylesheet " href="Goldfish. css" />

    <style type="text/css">
    <!--
    A {text-decoration:none }
    -->
    </style>

    </head>
    <body>

    <div id="container" >

    <div id="banner">
    <img src="images/banner.jpg" alt= "Goldfish Graphics Banner Image" />
    </div>


    <div id="navigation" >
    <div id="hvan">
    <a href="index.php ">Home</a> &nbsp; &nbsp; &nbsp; &nbsp; <a href="services. php">Services</a> &nbsp; &nbsp; &nbsp; &nbsp; <a href="portfolio .php">Portfolio </a> &nbsp; &nbsp; &nbsp; &nbsp; <a href="contact.p hp">Contact</a>
    </div>
    </div>


    <div id="sidebar">

    <div id="texto">

    <h4 class="sidebar" > Testimonies</h4>
    <p>
    <?php include('testmo nies.php'); ?>

    </p>

    </div>
    <h4>Links</h4>

    <div id="links">

    <div class="nav">
    <p>
    <a href="#">Pixel2 Life</a>
    <br />
    <a href="#">Link</a>
    <br />
    <a href="#">Link</a>
    <br />
    <a href="#">Link</a>
    </p>
    </div>


    </div>
    </div>



    <div id="content">
    <div id="text">
    <h2>Contact</h2>
    <p id="home">
    <form id="feedback" method="post" action="">
    <p>
    <label for="name">Name :</label>
    <input name="security" id="security" type="text" class="name" />
    </p>
    <label for="email">Ema il:</label>
    <input name="security" id="security" type="text" class="email" />
    <p>
    <label for="comments"> Prodject Description:</label>
    <textarea name="security" id="security" cols="54" rows="5">
    </textarea>
    </p>
    <p>
    <input name="send" id="send" type="submit" value="Submit" />
    </p>
    </form>

    <?php
    if ($_POST && !$mailSent) {
    ?>
    <p class="warning" >Sorry, there was a problem sending your message. Please check to make sure you filled out all the required entries.</p>
    <?php
    }
    elseif ($_POST && $mailSent) {
    ?>
    <p><strong>Yo ur message has been sent. Thank you.</strong></p>
    <?php } ?>




    </p>


    <p id="news">

    </p>
    </div>
    </div>

    <div id="footer">
    </div>



    </div>







    </body>
    </html>[/code]

    The problem is it's not actually sending anything to my email. This might be because I am doing it on a local host, the other thing is whenever I summit any kind of information this error message pops up at the top of my site...


    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\wamp\www\Gol dfish Graphics\contac t.php on line 21

    I want to know how to make that not happen, I want to know how to make the information actually go to my email, and I don't really understand how to make my forms safe from hackers. I basically went through a tutorial and found this.
    [code=php]
    <?
    function secured($val)
    {

    if(empty($val) or strlen($val) > 40)
    {
    return false;
    } else {
    $val = strip_tags(
    trim(($val)
    )
    )
    ;

    $val = escapeshellcmd( $val);
    return stripslashes($v al);
    }
    }
    ?>[/code]

    I have that saved in a php file as security and in my code above you can see I have the name and id of the input fields as security. Does this work?
    Last edited by pbmods; Jul 19 '07, 11:54 PM. Reason: Added CODE tags.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Please use CODE tags when posting source code. Thanks!

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Bouzy.

      To get mail() to work on Windows, you have to futz around with your php.ini file.

      Check out this article.

      Comment

      • tscott
        New Member
        • Jul 2007
        • 22

        #4
        Hey,
        I found a slight problem you had with defining your variables. The way you did it, it would litterally look like this if you printed them. Name: $name
        [PHP] $message = "Name: $name\n\n";
        $message .= "Email: $email\n\n";
        $message .= "Project Idea: $comments";[/PHP]
        Try doing it this way.
        [PHP]$message = "Name:" . $name . "\n\n";
        $message .= "Email:" . $email . "\n\n";
        $message .= "Project Idea:" . $comments;[/PHP]

        The way you did it would not show the contents of the variable but rather just show it as plain text. If I'm wrong, please correct me, I learnt PHP this way.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          This is actually not correct.

          There is a difference between single quote marks '...' and double quote marks "...".
          The single quote marks will always print precisely what you put into them, while the double quote marks will parse variable names into their respective values.

          So basicly:
          [code=php]
          $var = "Hello";
          echo "var = $var"; // outputs: var = Hello
          echo 'var = $var'; // outputs: var = $var
          [/code]

          Comment

          Working...