Newsletter Management Using PHP w/o mySQL for Beginners

Let's begin by setting some limits. If you're like me, you like to keep it simple. All we're doing is collecting email addresses together for our mailing list, so biochemical engineering is out the window. If you're using Thunderbird (or that MS product), you can send nicely formatted newsletters out and retain all of the other awesome features of your email program so there's really no need for databases, logins, or pretty much anything else. We're going to stay far away from anything non-essential.

To keep it simple, I'll assume you have Dreamweaver or a comparable WYSIWYG composer; however, if you are editing source code you can click here to see an expanded version of this article with source code. Also, I've assumed that you have an extremely basic familiarity with PHP. If not, please begin by reading this PHP introduction (for absolute beginners).

There are only 3 steps we're going to need:

  • Put HTML on the page to collect the user's name and email address.
  • Add in a little PHP and (possibly) change a filename.
  • Receive and process the emails.
  • Marching on, we need to put some HTML on our page to let the visitor enter in their name and email address. To do this using Dreamweaver, you'll need to create a form with the POST method, a text input named visitor_name, a text input named visitor_email, and a submit button.

    We now have our excellent mailing list form up and you should check to make sure that it ended up where you planned. At this point, you may need to make another slight change. If the file's extension is not php, php3, php4, or phtml you should change the file's extension to php. Now, you will need to be careful here as file extensions are extremely important, so you may lose functionality when you change the file's extension. If this is the case, look up the extension and find a tutorial for the language.

    Take a breather and get ready for step 2. Since this is a PHP tutorial, we're going to take a closer look at the PHP code used to send us the email. Being a language, we'll need to learn enough of the PHP vernacular to 1) use the information the user submitted, 2) create the body of the email, and 3) send the email.

    The form we created sends 2 pieces of information: visitor_name and visitor_email. When PHP receives them it realizes that someone POSTed some information and to make it easy for you to get ahold of it creates a couple of special "things" you can use to refer to what the user entered: $_POST['visitor_name'] and $_POST['visitor_email']. Why does it call them by funny names? Well the $_POST part assures you that it was information that was submitted by your visitor and not some other PHP somewhere on your page. The part in quotes allows you to pick which piece of information was submitted by your visitor (don't stress on the brackets - they just separate the two pieces of information).

    Great! We now have our visitor's information, so let's send it to ourselves. Sending email in PHP almost seems too easy. We just need to modify this line mail(TO, SUBJECT, MESSAGE); by replacing each of the bold capitalized words and adding this inside of PHP tags to our page. Replace TO with your email address in quotes. Replace SUBJECT with the subject you want to appear on the email inside of quotes. In an effort to keep it simple, replace MESSAGE with "{$_POST['visitor_name']} at {$_POST['visitor_email']} would like to subscribe to your mailing list." By now, the MESSAGE replacement is probably self-explanatory except for the curly braces. The curly braces just reassure PHP that the information inside of them really does refer to something it should already know (in this case what our visitor submitted).

    Now we just need to include our modified line in the HTML page. Here's the whole modified line (don't forget the PHP tags!):

    mail("MY EMAIL ADDRESS","Newsletter Subscription","{$_POST['visitor_name']} at {$_POST['visitor_email']} would like to subscribe to your mailing list.");

    If you're a really observant reader, you're already wondering how PHP knows to wait until someone's submitted a subscription request. Well, in the example above, it doesn't. It's also missing some kind of message to inform your subscriber that their request was successful. Since this is introductory material and already lengthy, I'll save that explanation for another article. Just follow everything you've learned above and use this line of code instead (I've bolded my special addition), substituting the success message for one of your own:

    if (isset($_POST['visitor_email'])) { mail("MY EMAIL ADDRESS","Newsletter Subscription","{$_POST['visitor_name']} at {$_POST['visitor_email']} would like to subscribe to your mailing list."); echo "Subscription Complete. Thank you!"; }

    Er, that's all folks! You'll start receiving emails which you can then add to a mail list in Thunderbird. To manage unsubscription requests, just have a little note at the end of your mailing list saying to reply to the email to be removed and then edit your mailing list.

    Jeremy Miller - Webmaster of Script Reference - The *NEW* PHP Reference & Tutorial Site For Non-Programmers

    In The News:


    pen paper and inkwell


    cat break through


    Why to Have a Website for Your Company

    After having decided to start a business, the next thing... Read More

    Ten Quick Tests To Check Your Website For Accessibility

    The Disability Discrimination Act says that websites must be made... Read More

    Web Accessibility: The Basics

    What is web accessibility & why is it important?Web accessibility... Read More

    Do Dancers Need A Website?

    Dance is how you pamper your soul and satiate your... Read More

    Six Basic Reasons Why Visitors Stay On Your Web Site

    1. The first page appears quickly.It's a good way to... Read More

    The Most Important Aspect of Writing Web Copy

    There is an ongoing debate about web copy. Some say... Read More

    I Want To Be A Freelancer

    So you have decided that you want to do freelance... Read More

    5 Tips To Supercharge Your Website Sales Copy

    The art of turning website visitors into paying customers depends... Read More

    From Concept to Website

    You've decided to create a website to market your products... Read More

    Beware the Software Siren

    I've heard several prominent web marketers mention in their classes... Read More

    Build a Strong Foundation for Creating Your First Online Identity ? Notes for Beginners

    If you are looking for creating your online presence you... Read More

    Have You Got Your Ear To The Ground Or Your Head In The Sand?

    What happened on your website yesterday? What about last week... Read More

    Art, Artists, and the Web:Part: 2--First Steps in Building an Artist?s Website

    What you should do and know if you are an... Read More

    Live Support from Your Website? Can You Do It for Free?

    I'm a freelance programmer and somehow I managed to get... Read More

    Why Is No-one Buying From My Website?

    Are you, like many other website owners, frustrated at the... Read More

    Free Isnt Always Good - 5 Reasons Why You Need Your Own Website

    Often time I've browsed sites and seen the same thing... Read More

    How to Handle Web Surfers Who Disabled JavaScript

    There are hundreds of millions of Web surfers today. Each... Read More

    But My Business Doesnt Need A Website!

    Revenues are often lost because many business owners don't see... Read More

    Why Local Service Companies Should Have a Website

    The Internet is being used by local service business to... Read More

    Five Essential Questions to Answer Before Creating Your First (or second...or third) Website

    Right after the thought, "I need a website," people usually... Read More

    Improving Usability for Screen Reader Users

    Simply ensuring your website is accessible to screen reader users... Read More

    Let Your Customers Redesign Your Website!

    When you purchase a new item from a Yahoo! Store,... Read More

    Server Stats ? Analyzing Traffic To Your Site

    Analyzing traffic to a site is a key factor in... Read More

    The Two Most Common Mistakes That Scare Away Web Visitors

    Can you imagine the hypocrisy of spending thousands of dollars,... Read More

    Five Question-Five Minute Web Makeover Quiz

    If you haven't made the sales and built your clients... Read More

    Why You Need A Web Site

    "I have a small business with just a couple of... Read More

    Set Up Your Website in Minutes ? For Free

    There was a time not long ago when setting up... Read More

    Freelance Programming is Easy to Manage

    There are several reverse bid freelance sites out there. Beyond... Read More

    The Disability Discrimination Act (DDA) & Web Accessibility

    There's been widespread speculation about the new legislation being introduced... Read More

    5 Ways to Build a Website

    If you are like me you have wanted to build... Read More

    Seven Daft Things Not To Do To Your Website

    1. Splash pagesMost of the time splash pages are uncalled... Read More

    Is Your Web Site Talking to Your Customer?

    A while ago one of my clients approached me and... Read More

    50 Ways To Use Your Website

    A website is the most versatile and cost-effective marketing tool... Read More