Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Simple 'Join Email List' script or contrib


dragon5

Recommended Posts

Hello. I'm looking for a contrib or script to add to my store to allow people to add their email address to my newsletter db. The addition of a simple 'Join Email List' box on my home page would be ideal, allowing visitors to the site the ability to add their email address to receive my quarterly newsletter. Obviously, Existing customers are already in the db. I'm looking to capture potential new customers.

Thanks

Tom

Link to comment
Share on other sites

  • 3 weeks later...

What I've been doing is capturing names and email addresses in a seperate database. Although this has been the easiest way to do things up until now, I've run into a couple problems.

 

SPAM. Garbage emails etc shows up

 

Customers think they are already in the database so when they find their account does not exist they abandon their cart.

 

I have moved towards modifing the existing signup form to allow for less details during signup.

 

This in itself is probly the most practical method.

 

After all, when a subscriber moves to purchase, all they have to do is add mailing information.

 

Thomas

A signature is something that reflects its user. - The dictionary

 

The question is not, 'to code, or not to code'

the question is, 'if we do not code, are we really alive?'

-- anonymous

Link to comment
Share on other sites

Thanks Tom. Here is a simple php script that I came across that will do what I need. I just haven't figured out how to implement yet. My php skills are limited. Since addresses go to a text file, should be simple to remove the SPAM. You can limit the # of emails posted to the file as well.

 

Tom

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="robots" CONTENT="NOINDEX,NOFOLLOW">

<title>E-Mail Subscriber List</title>

<link rel="stylesheet" type="text/css" href="email.css">

</head>

<body>

<h3><u>E-Mail Subscriber List</u></h3><br>

<?php

 

 

########

# INFO #

########

 

/*

Title:

E-Mail Subscriber List (I Guess?)

Call it whatever you'd like...

 

Author:

Eric O'Callaghan

 

Date Created:

August 10, 2006 (Friday)

 

Requirements:

PHP

SMTP

 

Installation:

1. You'll have to put this PHP file on your website

2. You will have to make a file to store the email addresses in (and chmod it to 0666)

The file is "emails.txt" by default, or you can change it in the variables section if you'd like

3. You can create a CSS file to style the page if you'd like (email.css by default, or you can change the filename at the top of this script)

A good example is at

4. It's suggested to add an e-mail address and try sending something to it

5. Do whatever

 

 

Notes:

 

Feel free to edit this script, but if you've found a great

way to improve upon it, go ahead and email me

with your changes and I'll update it on the website

and give you plenty of credit.

 

A single e-mail address cannot be added to the list twice.

 

The administrator password (which you change in the variables section)

is entered as if you were going to add an e-mail address, but when submitted it will

take you to a form so that you can send an e-mail to all of the addresses in the list.

 

To remove an e-mail address from the list, you will have to manually edit the file

(emails.txt or whatever you change it to in the variables section)

 

Bugs:

 

Thanks to Simon Evans for pointing out that there was an error

with the success message after sending e-mail from the admin area!

 

Thanks to Thomas McCartney for multiple suggestions!

 

 

Enjoy..

*/

 

##########################

# VARIABLES - EDIT THESE #

##########################

 

// What do you want the administrator password to be (to send emails)?

// Enter the password into the form to add an e-mail address and it will give you a form to send email to the users

$adminpass = "password";

 

// What do you want the From address for emails sent from the script to be?

$fromemail = "[email protected]";

 

// What's the name of the file emails will be stored in?

$file = "emails.txt";

 

// How many e-mail addresses should the file be limited to?

// Set to 0 for unlimited

$limit = "100";

 

############################

# BE CAREFUL EDITING BELOW #

############################

 

// Create function to limit number of addresses

function checklimit ($limit) {

 

// Get filename and limit

global $file;

 

// Find number of lines in file

$lines = file($file);

$num_lines = count($lines);

 

// Error if limit reached

if ($limit == "0") {

$limitreached = "NO";

} elseif ($num_lines >= $limit) {

$limitreached = "YES";

} else {

$limitreached = "NO";

}

 

// Return error

return $limitreached;

}

 

// Process the form to send email if submitted

if (($_GET['do'] == "send") && ($_POST['password'] == $adminpass) && (isset($_POST['subject'])) && (isset($_POST['body']))) {

 

// Open the list

$fh = fopen($file, "a");

if ($fh) {

 

// Get the contents of the list

$data = file($file);

 

// Pick out each email in the list

for ($n = 0; $n < count($data); $n++) {

$line = explode("\n", $data[$n]);

 

// Send an email to each individual address in the list

mail($line[0], $_POST['subject'], $_POST['body'], "From: $fromemail");

}

 

// Success message

$msg = "The e-mail was sent to all addresses on the list.";

 

// Error if list can't be opened

} else {

$error = "Sorry, the mailing list cannot be accessed - please try again later.";

}

 

// Close the list

fclose($fh);

 

// Process the form to add an email if submitted

} elseif (($_GET['do'] == "add") && (isset($_POST['email']))) {

 

// Replace the < and > in e-mail address for showing on HTML page

$lefttag = "<";

$righttag = ">";

$EmailFix = str_replace("<", $lefttag, $_POST);

$EmailFix = str_replace(">", $righttag, $EmailFix);

 

// Check if admin

if ($_POST['email'] == $adminpass) {

 

// Show form to send email

echo "<form method=\"POST\" action=\"" . $_SERVER['PHP_SELF'] . "?do=send\">\n";

echo "<input type=\"hidden\" name=\"password\" value=\"$_POST\">\n";

echo "Subject:<br>\n<input type=\"text\" name=\"subject\"><br>\n";

echo "Body:<br>\n<textarea name=\"body\" cols=\"50\" rows=\"20\"></textarea><br>\n";

echo "<input type=\"submit\" value=\"Send\">\n";

 

// End the script

echo "</body>\n";

echo "</html>\n";

exit;

 

// Check address limit

} elseif (checklimit($limit) == "YES") {

$error = "Sorry, the limit of e-mail addresses allowed has been reached and new addresses cannot be added at this time.";

 

// Check the email

} elseif (!eregi("^([a-z ])*(<)?[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}(>)?$", $_POST['email'])) {

$error = "Please enter a valid e-mail address.";

 

// Add the email if it doesn't already exist

} else {

 

// Open the list

$fh = fopen($file, "a");

if ($fh) {

 

// Get the contents of the list

$data = file($file);

 

// Compare each email in list with the one being entered

for ($n = 0; $n < count($data); $n++) {

$line = explode("\n", $data[$n]);

 

// Error if email being entered matches one in the list

if (eregi("^(\\$_POST)$", $line[0])) {

$emailexists = "yes";

$error = "That e-mail address $EmailFix is already in the list.";

}

}

 

// Error if list can't be opened

} else {

$emailexists = "yes";

$error = "Sorry, the mailing list cannot be accessed - please try again later.";

}

 

// Write to file if email doesn't already exist

if ($emailexists != "yes") {

 

// Write to the list and give success message

fwrite($fh, "$_POST\n");

$msg = "Your e-mail address $EmailFix was successfully added to the list!";

}

 

// Close the list

fclose($fh);

}

}

 

// Show any errors encountered

if (isset($error)) {

echo "<font color=\"red\"><b>" . $error . "</b></font><br><br>\n";

 

// Show success message if there was one and end script, and no errors were encountered

} elseif (isset($msg)) {

echo "<b>" . $msg . "</b>\n";

echo "</body>\n";

echo "</html>\n";

exit;

}

 

?>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?do=add">

Email Address: <input type="text" name="email"><br>

<input type="submit" value="Submit">

</form>

</body>

</html>

</body>

</html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...