1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

email me form in HTML?

Discussion in 'Web Design & Development' started by cnelson04, Jan 11, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. cnelson04

    cnelson04 Thread Starter

    Joined:
    Dec 28, 2003
    Messages:
    896
    ok, here what i want to, when you click the submit button it should email me your email addres except i don't want it to open up an email program i just want it to email it from the websever. is this possible? heres the code..

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>MusicJunkie.be Early '06</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <center><img src="intro%20copy.jpg" width="700" height="500"></center></body>
    <br>
    <center><form action="MAILTO:[email protected]" method="post" enctype="text/plain">
    <h4>E-Mail me when the site is done!<h4>
    <font="Comic Sans" size="3">Your E-mail:<br>
    <input type="text" name="mail"
    value="your email" size="40">
    <br>
    <input type="submit" value="send">
    </font></center>
    </html>

    thanks -cnelson. :)
     
  2. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    It cant be done in html because modern browsers no longer support email forms in html.
    It wont run unless you have a perl script to execute the html document.
    A good example of this is Matts formail
    http://www.scriptarchive.com/formmail.html

    Does your host support php? it can be doen easily in php
     
  3. cnelson04

    cnelson04 Thread Starter

    Joined:
    Dec 28, 2003
    Messages:
    896
    yes i do have php. could you maybe show me an example of how to do it? -cnelson. :)
     
  4. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    Heres a simple way, please change the email in $sendto ="[email protected]" to where you want the form to send
    PHP:
    <?php
      
    // if submitted form process and send mail
      
    if ($REQUEST_METHOD == "POST") {

        
    // just to be on the safe side
        // I'll strip out HTML tags
        // (scripting code may mess with some email clients)
        
    $realname strip_tags($realname);
        
    $email strip_tags($email);

        
    $sendto "[email protected]";
        
    $subject "Website Feedback ";
        
    $message "$realname$email\n";

        
    mail($sendto$subject$message);

      }

    ?>

    <html>
    <head>
      <title>insert title here</title>
      <meta name="author" value="insert name here">
      <meta name="copyright" value="(c) 2005 JoyCo Design">
    </head>
    <body bgcolor="#FFFFFF">

    <h2>Send Mail When site complete</h2>

    <p>An easy way to get feedback on a site is to have
    it emailed to you. This script shows you how to create
    a Feedback form with the response being emailed to you
    using PHP.</p>

    The first thing we need is our HTML form.
    Keeping it simple I'll only ask for Name and Email. Use your browser's view source
    if you would like the HTML code.
    <hr size="1" noshade></p>

    <?php
        
    // if submitted form display sent message
        
    if ($REQUEST_METHOD=="POST") {
            echo(
    "<P><b>Message Sent</b></p>\n");
            echo(
    "<blockquote><pre>\n");
            echo(
    "$message");
            echo(
    "</pre></blockquote>");
        }
        
    // if not display form
        
    else {
    ?>
    <!-- ***  START HTML FORM -->
      <form action="<?php echo("$script_name"); ?>" METHOD="POST">
      <table cellpadding="4" cellspacing="0" border="0">
        <tr><td><b>Name: </b></td><td><input type="text" name="realname" size="25"></td></tr>
        <tr><td><b>Email:</b></td><td><input type="text" name="email" size="25"></td></tr>
        <tr><td colspan="2" align="right"><input type="submit" value="Submit"></td></tr>
      </table>
      </form>
    <!-- *** END HTML FORM -->

    <?php ?>
    <hr size="1" noshade></p>

    </body>
    </html>
     
  5. jiml8

    jiml8 Guest

    Joined:
    Jul 2, 2005
    Messages:
    2,634
    Matt's formmail is insecure and can be used as an open relay. Don't use it.

    There are other mailers out there, including the nms Formmail which can be configured as a drop in replacement for Matt's and which is secure.
     
  6. jiml8

    jiml8 Guest

    Joined:
    Jul 2, 2005
    Messages:
    2,634
    You sure this isn't a syntax error? Seems to me that an open brace in an if...else statement, followed by the end of the PHP section should be a syntax error, though I haven't tried it.

    Seems to me to avoid the syntax error you need to echo the form HTML into the stream from PHP. This way the closing brace is part of the same PHP module.
     
  7. jiml8

    jiml8 Guest

    Joined:
    Jul 2, 2005
    Messages:
    2,634
    Well, I just tried it on one of my servers, and it worked as writtten. You learn something new every day. :)
     
  8. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    EDIT: sorry, didnt see you already tested it, posted at same time as yours I guess.

    The code is fine as far as I know.

    The if statement is to submit the data from the form in the page, the else is to display the form again if not filled out, I didn't write in an error process, just a returned blank form.
    I was trying to keep it very simple. I am not certain however how secure this is to defy spam, I usually process through a seperate php script that handles spam and errors better. WHat do you think about security of this code?
     
  9. TechGuy

    TechGuy Administrator

    Joined:
    Feb 12, 1999
    Messages:
    14,195
    First Name:
    Mike
    This is actually one of the wonderful things about PHP -- it will hold the statement open until you bring it back to <?php -- no syntax error there, and it makes it much easier to enter HTML without worrying about quotes or strange pipes.
     
  10. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    Thanks for the support!

    Again any advice as far a bots? does this look ok?
     
  11. TechGuy

    TechGuy Administrator

    Joined:
    Feb 12, 1999
    Messages:
    14,195
    First Name:
    Mike
    Because the Send To address is hard coded into the PHP file (and not a variable sent with the message, from address, etc), they can only spam you. I doubt this will cause much trouble for you.
     
  12. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    Thanks for the tip, then thats settled.
     
  13. jiml8

    jiml8 Guest

    Joined:
    Jul 2, 2005
    Messages:
    2,634
    Ummm...

    They could insert a bcc or any header into the text of the message and relay that way. Known issue with PHP mail() function. Need some pretty smart code to keep that from happening.

    I think it is cool that PHP will hold a clause open that way. I didn't know about it because I wouldn't ordinarily program that way. Were I to write it, I would have embedded the HTML in PHP and escaped the quotes wherever needed.

    I do agree that it is more readable the way it is done here and I'll keep that in mind in the future.
     
  14. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    Thanks, can you give it a try on this form, I would like to see what you mean

    spam it to removedemail

    Thanks
     
  15. TechGuy

    TechGuy Administrator

    Joined:
    Feb 12, 1999
    Messages:
    14,195
    First Name:
    Mike
    Hmm, guess that could be possible, but I'm not completely convinced yet. ;) Maybe strip_tags($message) would help... Not sure.
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/433323

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice