include('maillist/config.inc.php');
$connection = mysql_connect($db_server, $db_user, $db_password) or die("Could not connect : " . mysql_error());
mysql_select_db($db_name) or die("Could not select database");
/*
check address for basic validity. if ok proceed, if not, return message and exit
if valid, insert in db with random md5 key of something (time?) and send email to address with link back to confirm.php
*/
$headers = "From: $owner_email\r\nReply-To: $owner_email";
function validate_email($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_{|}~-][A-Za-z0-9!#$%&'*+/=?^_{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
if ($_POST[address]) {// Submitting sub/unsub request from web page
$email = $_POST[address];
$blacklisted = false;
$blacklist_query = "SELECT * FROM mailinglist_blacklist";
$blacklist_result = mysql_query($blacklist_query) or die("Query5 failed : " . mysql_error());
while ($blacklist_row = mysql_fetch_assoc($blacklist_result))
{
$pos = strpos($email, $blacklist_row[rule]);
if ($pos !== false)
{
$blacklisted = true;
}
}
if (validate_email($email) And !$blacklisted)
{
// Email is potentially valid
// See if in db, if so, send unsub email
// if not in db, insert record and send sub email
$key = md5(time());
$auth_link = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?address=$email&key=$key";
$req_time = time();
$query = "SELECT * FROM mailinglist_subscribers WHERE address = '".addslashes($email)."'";
$result = mysql_query($query) or die("Query1 failed : " . mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows == 1) // Record exists in db, send unsub email
{
$row = mysql_fetch_assoc($result);
if ($row[confirmed] == 1)
{
$subject = "Please confirm your unsubscribe request from $list_name";
$action = "unsubscribe from";
$auth_link = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?address=$email&key=$row[userkey]&c=0";
}
else
{
$subject = "Please confirm your subscribe request from $list_name";
$action = "subscribe to";
$auth_link .= "&c=1";
$query = "UPDATE mailinglist_subscribers SET userkey='$key', last_sub_req_date='$req_time' WHERE address = '".addslashes($email)."'";
$result = mysql_query($query) or die("Query2 failed : " . mysql_error());
}
}
else // no record in db, insert record and send sub email
{
$query = "INSERT INTO mailinglist_subscribers VALUES ('".addslashes($email)."', '$key', '0', '$req_time', '0')";
$result = mysql_query($query) or die("Query3 failed : " . mysql_error());
$subject = "Please confirm your subscribe request to $list_name";
$action = "subscribe to";
$auth_link .= "&c=1";
}
$message = "To confirm the request to $action the list: $list_name, ";
$message .= "we ask that you follow this link:\n\n$auth_link\n\nIf you are unable to click ";
$message .= "the link, please copy and paste it into your web browser.\n\n";
$message .= "$owner_email\n";
mail($email, $subject, $message, $headers);
$status_message = "A confirmation email has been sent to $email.";
}
else
{
// Email is invalid
$status_message = "We're sorry, this email address seems to be invalid or it's not allowed to sign up for this list.
Please check the address and try again or email $owner_email for assitance.";
}
#echo $status_message;
}
elseif($_GET) // Confirming a sub/unsub request from a link
{
$email = trim($_GET[address]);
$key = trim($_GET[key]);
$confirm = trim($_GET[c]);
$query = "SELECT * FROM mailinglist_subscribers WHERE address = '".addslashes($email)."' AND userkey = '$key'";
$result = mysql_query($query) or die("Query4 failed : " . mysql_error());
if(mysql_num_rows($result)) // The address and key match a record in the db. Proceed to verify request.
{
// if db has 0 and user has 0, that's an attempt to unsubscribe an unconfirmed address - denied
// if db has 0 and user has 1, that's an attempt to confirm an unconfirmed address - allowed
// if db has 1 and user has 0, that's an attempt to unsubscribe a confirmed address - allowed
// if db has 1 and user has 1, that's an attempt to subscribe a confirmed address - denied
$row = mysql_fetch_assoc($result);
if($row[confirmed] == 0 And $confirm == 1)
{
// user is in db, email and key are correct, they have not confirmed so this is a confirmation,
// update confirm and present message
$query = "UPDATE mailinglist_subscribers SET confirmed = '1' WHERE address = '".addslashes($email)."' AND userkey = '$key'";
$result = mysql_query($query) or die("Query6 failed : " . mysql_error());
$confirm_message = "Thank you, your subscription to $list_name has been confirmed. To unsubscribe at any time ";
$confirm_message .= "just enter your email address below.\n";
if($notify_on_confirm)
{
// Count subscribers for admin email
$count_query = "SELECT COUNT(*) FROM mailinglist_subscribers WHERE confirmed = '1'";
$count_result = mysql_query($count_query) or die("Query failed : " . mysql_error());
$count_confirmed = mysql_fetch_row($count_result);
$admin_note = "$email has joined $list_name. There are now $count_confirmed[0] members subscribing to this list.";
mail($owner_email, "$list_name Subscription Confirmation", "$admin_note", $headers);
}
if($notify_user_on_confirm)
{
$user_note = "Thank you for joining the $list_name list.";
mail($email, "$list_name Subscription Confirmation", "$user_note", $headers);
}
}
elseif($row[confirmed] == 1 And $confirm == 0)
{
// user is in db, email and key are correct, they were already confirmed so this is an unsubscribe req
// remove user from db and present message
$query = "DELETE FROM mailinglist_subscribers WHERE address = '".addslashes($email)."' AND userkey = '$key'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$confirm_message = "Thank you, you have been unsubscribed from $list_name.";
if($notify_on_unsub)
{
// Count subscribers for admin email
$count_query = "SELECT COUNT(*) FROM mailinglist_subscribers WHERE confirmed = '1'";
$count_result = mysql_query($count_query) or die("Query failed : " . mysql_error());
$count_confirmed = mysql_fetch_row($count_result);
$admin_note = "$email has unsubscribed from $list_name. There are now $count_confirmed[0] members subscribing to this list.";
mail($owner_email, "$list_name Unsubscription", "$admin_note", $headers);
}
if($notify_user_on_unsub)
{
$user_note = "You have been successfully unsubsribed from the $list_name list.";
mail($email, "$list_name Unsubscription Confirmation", "$user_note", $headers);
}
}
else
{
// one of the two denied conditions above occurred.
$confirm_message = "Error processing request. Please contact $owner_email for assistance.\n";
}
}
else
{
// No record found to confirm or unsubscribe in db
$confirm_message = "Error processing request. Please contact $owner_email for assistance.\n";
}
#echo $confirm_message;
}
?>
Join the Freaks list - the original Marillion and Fish (and associated bands) discussion list. Now reborn!
FishHeads mailing list
if(isset($status_message)){
echo "
$status_message
";
}?>
if(isset($confirm_message)){
echo "
$confirm_message
";
}?>
FishHeads is a way for Fish to send messages to everyone who is subscribed. The quantity of e-mail is not as high as a mailing list. The list of subscribers is private and will never be distributed to any other source.
To join, simply enter your email in the following form.
All subscribe/unsubscribe requests must be confirmed via email.
To unsubscribe, simply fill in the form using the same email address that you subscribed with.
If your email address is going to change and you want to keep receiving the FishHeads posts, you should unsubscribe your original email address, and subscribe with your new email address.