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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Simple newsletter subscription form

    I've been scouring the web for a tutorial or code that will enable my "subscribe to my newsletter" to send an email to a certain account, but I am in the very beginnings of web dev, so have no idea on PHP or whatever is needed. I litterally only know the basics of HTML.

    So, here is my form's code:
    Code:
    <form action="mail.php" method="POST" class="newsletter">
    	<h3>Subscribe to our Newsletter</h3><br>
    	<p>Be the first to hear about our new treatments, special offers and events</p></br>
    	<input type="text" name="email" placeholder="Enter email address" size=40 class="input"/>
    	<p><input type="submit" value="Subscribe" class="button" /></p>
    </form>
    I do not currently have a mail.php file, but from what I have read I need that? What code would go in that file?

    Also, if I'm using php, would I have to change the file type to .php, instead of .html?

    Please help.

    Thanks,

    Andy

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by _and_why_ View Post
    Also, if I'm using php, would I have to change the file type to .php, instead of .html?

    Yes ...... And to view the php file you must have php running for that directory. You can put everything into one php file, I would also consider sending sending an email to yourself notifying you when ever someone has subscribed.


    Untested, there might be syntax errors.

    subscribe.php
    PHP Code:
    <?php

    if (isset($_POST['email'])) {

    $to "$_POST['email']";
    $subject "";
    $message "";
    mail($to$subject$message);

    $your_email "your email";
    $subject_to_you "someone subscribed to your news letter";
    $message_to_you "";
    mail($your_email$subject_to_you$message_to_you);

    }
    ?>
    <html>
    <body>
    <form action="mail.php" method="post" class="newsletter" action="<?php echo $PHP_SELF;?>">
    <h3>Subscribe to our Newsletter</h3><br>
    <p>Be the first to hear about our new treatments, special offers and events</p></br>
    <input type="text" name="email" placeholder="Enter email address" size=40 class="input"/>
    <p><input type="submit" value="Subscribe" class="button" /></p>
    </form>
    </body>
    </html>


    ----
    Last edited by Len Whistler; 08-15-2012 at 08:52 PM.
    Leonard Whistler

  • Users who have thanked Len Whistler for this post:

    _and_why_ (08-17-2012)


  •  

    Posting Permissions

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