Newsletter Tutorial Part 1 The Signup

This newsletter tutorial will show you how to create a newsletter signup form, part 2 will show you how to send out newsletters from your list of users stored in a database.

You can see a Demo of the signup form in action

First we need a database table to store the signups create the following table in phpmyadmin:

the table stores a name and email address which can then be used to send out emails. The next part is to create the signup form, this is a standard form with a name and email fields the action is blank as the same page will process the form, the method is set to post so send the name and email securely.

To process the form we first check to see if the form has been submitted, this is done by using a function called isset then passing it the submit button name (in this case I called it submit)

if the form has been submitted then collect the name and email from the form

Next check the name is long enough and the email is in the correct format

If no errors have been created then carry on, otherwise the form stops here and the errors would be shown. Then insert the name and email address into the database table then show a success message or show an error if there is a problem, then close the two if statements.

If there has been an error then loop through all error arrays and show them

In it’s simplest form that’s all there is to making a newsletter signup, here’s the full script:

You can see a Demo of the signup form in action

if you’ve found this tutorial useful, please leave a comment.