Trying to set up database for newsletter and connect to subscribe form

Hi, so I have this template

and on the second page I need to set up the form so when people input their email they subscribe to my newsletter.

This is the “form.php” file that hes included:


$host = “host”; // DAtabase address
$username = “username”; // Databse username
$password = “password”; // Database password
$database = “dbname”; // Database name

$connect = @mysql_connect($host, $username, $password) or die (@mysql_error());
$selectdb = @mysql_select_db($database, $connect) or die (@mysql_error());

$email = $_POST[‘email’];

if (empty($email)) {
    $status = false;
    @mysql_query("INSERT INTO newsletter SET email='$email'");  // dont forget to change table name if you'll use another table name.
    $status = true;

echo $status;



I want to integrate that with my phplist.hosted database so people can input their email and automatically be added to the list.

If I need to make the database on my website that is fine too Im just a little unsure about the process.

Another thing you need to be aware if you’re creating your own newsletter list is the double opt in requirement and other record keeping requirements of the anti spam policy:

That’s very dangerous code - you need to validate the input - check out the php manual filter_var

if (empty($email)) {
    $status = false;


if (filter_var($email, FILTER_VALIDATE_EMAIL)) { $status = false; }

Please notify whoever gave you that code that it’s extremely dangerous.

Is this a WordPress site? If so, there are a several decent WordPress Newsletter plugins. For the last project I used a combination of: (to get SMTP rather than using phpmail)
and (which gave me the database, opt-in, unsubscribe and such)

I hacked them both up quite a bit, and added several fields to the database, but between the two of them and my hackery I have a very simple, light-weight newsletter subscription sign-up AND sending, with all required unsubscribe links and opt-in email.

There was another one I was looking at that had quite a lot of features:

but for my case, simple was better.

Thanks everyone for the help, no it isnt a wordpress site as of now. When I take down the splash page at launch and put up the shop it will be wordpress though.

Although I dont know much about php. I might just use phplist.hosted ajax subscribe box instead seems safer and a lot simpler, editing it might be hard though. Thanks everyone though.