Email form

Discussion in 'Web Design and Development' started by lexus, Sep 28, 2006.

  1. lexus macrumors 68000

    lexus

    Joined:
    Mar 26, 2006
    Location:
    Depends Greatly On The Weather
    #1
    Where can i find a secure form where people need only put there email address in and a compilation would be made from which i can send an email to all people who submitted their email address. Something like PHP list but alot simpler.

    Thank you
     
  2. Kunimodi macrumors member

    Joined:
    Sep 8, 2006
    Location:
    Ashland, OR, USA
    #2
    Hi, lexus. This depends on what services your host supports. Here are two easy ways that you can do this without relying on a external service:

    1. Put a form in the page that uses a get request so that the HTTP logs will show the e-mail:
    Code:
    <form action="nextstep.html">            
       <input type="text" name="myemail" />       
       <input type="submit" />            
    </form>
    Then you'll see something in the access logs along the lines of:
    [IP] - - [DATE] "GET /nextstep.html?myemail=me%40example.com HTTP/1.1" 404 215
    Though crude, this has the advantage of working on a server that does not allow server generated pages (e.g. PHP, ASP, cgi, etc).

    2. Bite the bullet and use a PHP or other server side script. Here is a very, very simple one-liner to do it:
    Code:
    <?php file_put_contents('emails.txt', $_GET['myemail'], FILE_APPEND); ?>
    You can use the form in step 1 and put the one-liner in nextstep.php (and change the form's 'nextstep.html' to 'nextstep.php'). This will append each e-mail to 'emails.txt'. For security, you can move 'emails.txt' to a directory protected with .htaccess, etc.
     
  3. lexus thread starter macrumors 68000

    lexus

    Joined:
    Mar 26, 2006
    Location:
    Depends Greatly On The Weather
    #3
    Thank you very much, could you explain how to do this using PHP a bit better, I am a total noob at this.

    Thanks
     
  4. ChicoWeb macrumors 65816

    ChicoWeb

    Joined:
    Aug 16, 2004
    Location:
    California
    #4
    http://mojo.skazat.com/

    They provide you frontend code for people to subscribe. Very easy to install and a great script.
     
  5. lexus thread starter macrumors 68000

    lexus

    Joined:
    Mar 26, 2006
    Location:
    Depends Greatly On The Weather
    #5
    Thank you, by the way if the didyougetthememo blog is yours how did you put the announcment on the top (through wordpress)?

    Thanks
     
  6. Kunimodi macrumors member

    Joined:
    Sep 8, 2006
    Location:
    Ashland, OR, USA
    #6
    Normally, PHP files are text files with a .php extension that the server has been set up to treat a little differently from regular .html, etc files. They are just like an HTML file except that anywhere in the HTML you can add a PHP block by putting inside of <?php ... ?>. The '...' is where you would put the PHP code. When a browesr requests that file, the server will replace all the PHP blocks with anything they output and send the result to the browser. For example,
    Code:
    <html>
      <body>
        <?php print('hello'); ?>
      </body>
    </html>
    will return a page that looks like this:
    Code:
    <html>
      <body>
        hello
      </body>
    </html>
    The neat part about this is being able to do dynamic stuff like
    Code:
    <html>
      <body>
        <?php print(15 + 15); ?>
      </body>
    </html>
    which produces
    Code:
    <html>
      <body>
        30
      </body>
    </html>
    When a user enters information into an html form the values they entered are automatically available to php with the special arrays _GET and _POST, which match the name in the originating form element. So if the entry page is this:
    Code:
    <html>
      <body>
        <form action="process.php" method="get">
          <input name="myemail" type="text" />
          <input type="submit" />
        </form>
      </body>
    </html>
    and process.php is:
    Code:
    <html>
      <body>
        Your email is <?php print($_GET['myemail']); ?>
      </body>
    </html>
    the page will show 'Your email is example@example.net' if a person entered 'example@example.net' into the entry page. We use this system to write to an email text file instead, doing it at the beginning of the processing:
    Code:
    <?php file_put_contents('secure/emails.txt', $_GET['myemail'] + "\n", FILE_APPEND); ?>
    <html>
      <body>Thank you for adding your e-mail.</body>
    </html>
    This would append the value of 'myemail' (and an end of line character) to the 'emails.txt' file in the folder named 'secure'.
     

Share This Page