It  is often required to have  Newsletter subscription form on the home page of your website.

For that i have written a small piece of code to demonstrate Newsletter subscription without page reload

The HTML part

<form id="signup" name="signup">
<input name="email" id="email" type="text" value="Email ID"  onblur="clearText(this)" onfocus="clearText(this)"  />
<input name="form_submit" id="form_submit" type="submit" value="Subscribe" />

The Javascript part

<script language="javascript" type="text/javascript">

$(function() {

var email = $("#email").val();

var dataString = 'email='+ email;

alert('Please provide email address');
type: "POST",
url: "newsletter-subscribe.php",
data: dataString,
cache: false,
success: function(html){


}return false;


The PHP part


$link = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_);
if (!$link) {
die('Could not connect: ' . mysql_error());

$db_selected = mysql_select_db(_DB_NAME_, $link);
if (!$db_selected) {
die ('Can't use : ' . mysql_error());

$query = sprintf("INSERT into ps_newsletter (email, newsletter_date_add, ip_registration_newsletter) VALUES ('%s', '%s', '%s')",
date('y-m-d h:i:s'),

// Perform Query
$result = mysql_query($query);


echo 'Thank you for subscribing to our Newsletter';

Get Free Email Updates!

Signup now and receive free offers, discounts & coupon codes

I agree to have my personal information transfered to Mad Mimi ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.