Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    63
    Thanks
    2
    Thanked 0 Times in 0 Posts

    I'd love some feedback on feedbacks...

    Hi. I want to add a fairly simple Feedback/Contact Me form to my website. All I really need are fields for visitors to enter their names, email addresses and comments, then click a Submit or Send button to email me. Everything I've found so far talks about PHP or CGI, disciplines in which I'm not well versed.

    Is there a way I can accomplish this with HTML/CSS? If not, is PHP difficult for an old man to learn?

    Thanks for any assistance.

    mccdaddy

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts
    The beauty of the internet is that you don't have to learn PHP to use it.

    If you are able to install a PHP PEAR application on your host (if you have the option in your cpanel, you probably can), I wrote just such a tutorial on the forum of my free webhost a few days back... http://www.websitesnetwork.com/forum...?showtopic=623 ...obviously the instructions on installing to the host and the account details over there may be different to the way it's done on your host, but the basics are the same.

    It's obviiously adapted to that particular host, but if you can install "PEAR mail" to your host, the script is all there for you, with instructions, and the SMTP server and login details will obviously be whatever they are on your host, rather than how things work over there.

    Failing that, there's a million and one tutorials on building a simple contact form out there using the standard mail() function of php. It's really not that hard. Most tutorials on it give the code for you, and if you read through that link I just gave for my own tutorial, it'll give you an idea of how it works if your stuck... really, the only potentially tricky bit is linking the html form to the php processing script, and that's not hard.

    Here's a couple of links for other tutorials on contact forms...
    http://www.thesitewizard.com/archive/feedbackphp.shtml
    http://www.tutorialguide.net/php_con..._tutorial.html
    http://www.ethicsdesigns.com/tutorial_contact_us.php
    Last edited by rhia; 10-21-2007 at 04:16 AM.

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    63
    Thanks
    2
    Thanked 0 Times in 0 Posts
    rhia,

    Thanks for your reply. I read your tutorial and viewed the links. I tried the simplest coding I could find, just to test if it would work.

    Code:
    <html>
    <body>
    
    "<?php
    //variables (change these)
    
    $youremail = "mccdaddy01@hotmail.com";
    // your email address
    
    $subject = "Contact";
    // the subject of the email
    
    $thankyou = "thankyou.php";
    // thank you page
    
    // don't change anything else
    
    ;if($email == ""){
    ?>
    No email address added. Please go back.<br/>
    "<?php
    ;}elseif($name == ""){
    "?>
    No name added. Please go back.<br/>
    <?php
    ;}elseif($message == ""){
    "?>
    No message added. Please go back.<br/>
    "<?php
    ;}else{
    
    $msg = ereg_replace("\\\'", "'", $message);
    $msg = ereg_replace('\\\"', "\"", $msg);
    $message1 = "from: $name\nemail: $email\nmessage:\n$msg1";
    
    mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
    ?>
    <meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">
    "<?php
    }
    "?>
    
    *You don't have to have a thank you page if you dont need it you can just 
    make it index.php or whatever page*
    
    Now for the form:
    
    <form action="mail.php" method="post">
    Name 
    <input type="text" name="name"><br/>
    Email addess 
    <input type="text" name="email"><br/>
    Message<br/>
    <textarea name="message" cols="40" rows="5"></textarea><br/>
    <input type="submit" value="send"><br/>
    </form>
    
    </body>
    </html>
    Unfortunately I get numerous error messages, among them "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/wayne/public_html/mail.php on line 27"

    I'm still reading and testing, trying to understand what I'm doing wrong.

    mccdaddy

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You just need to do a little revision to make this work. To fix the errors you need to split the code into two files (the tutorial doesn't explain this part very well). The <?php .... ?> is all part of one file for PHP, and the <form> part is in any separate file (for example contact.html). The error was that the tutorial put an extra " mark at the start of the PHP file. PHP files don't need the basic HTML tags, so don't add any of those to the .php file. PHP can display HTML, but thats beyond this issue and just realize for this you don't need it. The form will actually start in contact.html, will get sent to mail.php, and if the form is filled out the email will get sent. Otherwise it will give an error message and ask you to go back and fill in the missing information. So when you link to the page on your site, link to contact.html and people shouldn't ever go to mail.php except when the form sends their message. I hope that clears things up!

    mail.php

    Code:
    <?php
    //variables (change these)
    
    $youremail = "mccdaddy01@hotmail.com";
    // your email address
    
    $subject = "Contact";
    // the subject of the email
    
    $thankyou = "thankyou.php";
    // thank you page
    
    // don't change anything else
    
    ;if($email == ""){
    ?>
    No email address added. Please go back.<br/>
    "<?php
    ;}elseif($name == ""){
    "?>
    No name added. Please go back.<br/>
    <?php
    ;}elseif($message == ""){
    "?>
    No message added. Please go back.<br/>
    "<?php
    ;}else{
    
    $msg = ereg_replace("\\\'", "'", $message);
    $msg = ereg_replace('\\\"', "\"", $msg);
    $message1 = "from: $name\nemail: $email\nmessage:\n$msg1";
    
    mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
    ?>
    <meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">
    "<?php
    }
    "?>
    contact.html

    Code:
    <html>
    <header>
    <title>Email me!</title>
    </header>
    <body>
    
    <form action="mail.php" method="post">
    Name 
    <input type="text" name="name"><br/>
    Email addess 
    <input type="text" name="email"><br/>
    Message<br/>
    <textarea name="message" cols="40" rows="5"></textarea><br/>
    <input type="submit" value="send"><br/>
    </form>
    
    </body>
    </html>
    Last edited by gnomeontherun; 10-24-2007 at 06:26 AM. Reason: clarifications
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    New Coder
    Join Date
    Dec 2005
    Posts
    63
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I made the suggested changes and the Contact Form displays fine. However, when I complete the form and enter a valid email address I get this error message:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/wayne/public_html/mail.php on line 24

    mccdaddy

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ok I had just copied the code from the site assuming it worked. I've made a few revisions. I just like to use echo instead of closing the PHP and reopening it like this page does. Its not really a pretty solution, but this stays in the spirit of the original function.

    Code:
    <?php
    //variables (change these)
    
    $youremail = "mccdaddy01@hotmail.com";
    // your email address
    
    $subject = "Contact";
    // the subject of the email
    
    $thankyou = "thankyou.php";
    // thank you page
    
    // don't change anything else
    
    if($email == ""){
       echo "No email address added. Please go back.<br/>";
       exit();
    }
    elseif($name == ""){
       echo "No name added. Please go back.<br/>";
       exit();
    }
    elseif($message == ""){
       echo "No message added. Please go back.<br/>";
       exit();
    }
    else{
    
    $msg = ereg_replace("\\\'", "'", $message);
    $msg = ereg_replace('\\\"', "\"", $msg);
    $message1 = "from: $name\nemail: $email\nmessage:\n$msg1";
    
    mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
    
    echo "<meta http-equiv=\"refresh\" content=\"0; url=$thankyou\">";
    }
    
    ?>
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    New Coder
    Join Date
    Dec 2005
    Posts
    63
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Jeremy, I really appreciate you taking time to help me. Sadly I continue to have problems with this coding. When I uploaded the "mail.php" file just as you posted I got a message saying unable to locate "thankyou.php". Since I never created a "thankyou.php" I merely removed the line referring to it and reloaded it. Now the message I get says: "No email address added. Please go back."

    I entered a good email address so I'm confused by the error message.

    Again, I appreciate all the help you've given me.

    mccdaddy

    Code:
    <?php
    //variables (change these)
    
    $youremail = "mccdaddy01@hotmail.com";
    // your email address
    
    $subject = "Contact";
    // the subject of the email
    
    // don't change anything else
    
    if($email == ""){
       echo "No email address added. Please go back.<br/>";
       exit();
    }
    elseif($name == ""){
       echo "No name added. Please go back.<br/>";
       exit();
    }
    elseif($message == ""){
       echo "No message added. Please go back.<br/>";
       exit();
    }
    else{
    
    $msg = ereg_replace("\\\'", "'", $message);
    $msg = ereg_replace('\\\"', "\"", $msg);
    $message1 = "from: $name\nemail: $email\nmessage:\n$msg1";
    
    mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
    
    echo "<meta http-equiv=\"refresh\" content=\"0; url=$thankyou\">";
    }
    
    ?>

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ok, I found a better php form, which actually validates the email. I have tested it so its good. The version you had chosen actually only checks if the value of the fields was empty, and then the php program wasn't picking up the values, my apologies for not seeing that earlier. I was unable to test the code before.

    http://www.ibdhost.com/contact/

    Just use the contact.php and sendeail.php parts, and if you want to get rid of the drop down, delete these parts. You can make other changes, but you would probably want to put a little comment in the PHP code that says something like.

    // Script from IBDHost http://www.ibdhost.com/contact/

    contact.php

    Code:
    Attention:<br />
    <select name="attn" size="1">
    <option value=" Sales n Billing ">Sales n Billing </option>
    <option value=" General Support ">General Support </option>
    <option value=" Technical Support ">Technical Support </option>
    <option value=" Webmaster ">Webmaster </option>
    </select>
    <br /><br />
    sendeail.php

    Code:
    $attn = $_POST['attn'];
    
    $attn = $attn ; 
    
    Attention: $attn \n
    And change these values

    Code:
    $subject = "Feedback from $visitormail"; 
    
    mail("YourEmail", $subject, $message, $from);
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #9
    New Coder
    Join Date
    Dec 2005
    Posts
    63
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Jeremy, I am indebted to you, this one worked just fine. I very much appreciate the time and effort you put in to help me.

    mccdaddy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •