| Author | Post |
|---|
Firebrand Member
| Joined: | Thu May 15th, 2003 |
| Location: | United Kingdom |
| Posts: | 4 |
| Status: |
Offline
|
| Mana: |     |
|
Posted: Thu May 15th, 2003 11:50 am |
|
Hi guys,
On the http://www.wowwebdesigns.com/ there is a subscibe to newsletter button. How do I do this?
Ok i know that a scipt is involved, BUT how do I set it up? Are there any tutorials on this stuff?
Confused
Help greatly appreciated!
Cheers
|
Aycan Administrator
| Joined: | Wed Nov 29th, 2000 |
| Location: | Columbus, Ohio USA |
| Posts: | 146 |
| Status: |
Offline
|
| Mana: |     |
|
Posted: Sat May 17th, 2003 05:11 pm |
|
Welcome to the Wow Web Designs forums Firebrand,
There are ready-made scripts and remotely hosted solutions to manage newsletters. But we use a simple, custom PHP script and a MySQL database table to accept newsletter subscriptions.
First, we have a simple database table called NEWSLETTER, which can be created with the following comand in MySQL:
CREATE TABLE NEWSLETTER ( SUBSCRIBER_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, SUBSCRIBER_EMAIL VARCHAR(60) NOT NULL, SUBSCRIPTION_DATE DATE NOT NULL, PRIMARY KEY (SUBSCRIBER_ID) ); |
Second, there is the PHP code that handles our subscriptions. I removed all references to unessential functions in it. Save this as newsletter.php:
<?php
function validate_email_address($email) { if (!preg_match('/^[A-z0-9._-]+\@[A-z0-9_.-]+$/i', $email)) die("Invalid e-mail address"); }
function is_already_subscribed($email) { $result = mysql_query("SELECT SUBSCRIBER_EMAIL FROM NEWSLETTER " . "WHERE SUBSCRIBER_EMAIL='$email' LIMIT 1"); if (mysql_num_rows($result)) die("The e-mail address you have entered belongs to an existing subscriber."); }
function write_record($email) { $result = mysql_query("INSERT INTO NEWSLETTER (SUBSCRIBER_EMAIL, SUBSCRIPTION_DATE) " . "VALUES ('$email', '" . date("Y-m-d") . "')"); }
$email = trim($email); if (($subscribe) or ($email)) { validate_email_address($email); mysql_connect("localhost", "username", "password"); mysql_select_db("database_name"); is_already_subscribed($email); write_record($email); echo("Thank you for subscribing to our newsletter!"); }
?> |
Third, add the following form code to an HTML file to call newsletter.php:
<FORM METHOD="POST" ACTION="newsletter.php"> Subscribe to our newsletter - your e-mail: <INPUT TYPE="text" NAME="email" SIZE=25 MAXLENGTH=60> <INPUT TYPE="submit" NAME="subscribe" VALUE="Subscribe"> </FORM> |
and you are done! Just don't forget to replace the username, password and database_name at the bottom of newsletter.php.
|
marcelo Member

|
Posted: Mon May 19th, 2003 02:43 pm |
|
Great!
It would cool if showing the function that manage the Massive-Sending and Newsletter-Archiving too. 
|
Firebrand Member
| Joined: | Thu May 15th, 2003 |
| Location: | United Kingdom |
| Posts: | 4 |
| Status: |
Offline
|
| Mana: |     |
|
Posted: Mon May 19th, 2003 11:37 pm |
|
Cheers for the help there much appreciated!!
|
 Current time is 11:13 pm | |
|