Wow Web Designs Forums Home

Search
   
Members

Calendar

Help

Home
Search by username
Not logged in - Login | Register 


Subscibe to
 Moderated by: Aycan  

New Topic

Reply

Print
AuthorPost
Firebrand
Member
 

Joined: Thu May 15th, 2003
Location: United Kingdom
Posts: 4
Status:  Offline
Mana: 
 Posted: Thu May 15th, 2003 11:50 am

Quote

Reply
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

Quote

Reply
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


Joined: Fri Apr 25th, 2003
Location: Buenos Aires, Capital Federal Argentina
Posts: 72
Status:  Offline
Mana: 
 Posted: Mon May 19th, 2003 02:43 pm

Quote

Reply
Great!

It would cool if showing the function that manage the Massive-Sending and Newsletter-Archiving too. :P

 

Firebrand
Member
 

Joined: Thu May 15th, 2003
Location: United Kingdom
Posts: 4
Status:  Offline
Mana: 
 Posted: Mon May 19th, 2003 11:37 pm

Quote

Reply
Cheers for the help there much appreciated!!;)


 Current time is 11:13 pm




Powered by WowBB 1.7 - Copyright © 2003-2006 Aycan Gulez
Page processed in 0.1677 seconds (10% database + 90% PHP). 16 queries executed.