Use AJAX and PHP to Build your Mailing List

Status
Not open for further replies.

office politics

It's all just 1s and 0s
Messages
6,555
Location
in the lab
Use AJAX and PHP to Build your Mailing List
By Aarron Walter
November 1st 2006

Reader Rating: 9

An elegantly designed site filled with engaging content is worth very little without an interested audience. An opt-in mailing list is one of the most effective methods of making contact with your audience and driving repeat traffic to your site. If visitors enjoy and trust your site, they're likely to trust you with their email addresses -- after all, they'll want to be informed of new products, articles, or other relevant information. This is a great way to build relationships with your site's users, and encourage them to come back to your site again and again.

In this article, we'll learn to use AJAX to accept subscriptions to your mailing list without having to refresh the page; with this approach, your signup process will be quick and painless. Our AJAX sign up form will also be able to accept subscriptions from visitors who don't use modern, AJAX-capable browsers.

This article assumes that your mailing list is stored in a MySQL database, but as long as you have the necessary code to add addresses to your own mailing list, it should be easy for you to adapt the code presented in this article to your own signup process.

Before we get started, download the code, and take a look at what we'll cover in this tutorial.

The Big Picture
Our mailing list signup system has three key components:


An HTML form inside a PHP page receives the visitor's email address.

JavaScript will listen for the form submission, which will trigger the AJAX call to the server with the email address.

A simple PHP page on the server will receive the address. It will check the email address for errors, then store the address in a MySQL database. A success or error message will be sent back to the HTML page for user feedback.

We'll also ensure that this signup functionality is accessible to all, by writing a PHP-based sign up for users who don't have JavaScript enabled in their browsers.
 
Status
Not open for further replies.
Back
Top Bottom