subject = $subject; $confirm->mail_to = $email; $confirm->message = $message; $confirm->unsub_message = ""; $confirm->use_SMTP = ($config[use_SMTP] == 1) ? true:false; $confirm->send(); $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 $config[owner_email] for assistance."; } 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 = '$email' AND userkey = '$key'"; $result = mysql_query($query) or die("Query 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 = '$email' AND userkey = '$key'"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); $confirm_message = "Thank you, your subscription to $config[list_name] has been confirmed. To unsubscribe at any time "; $confirm_message .= "just enter your email address below.\n"; if($config['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 $config[list_name]. There are now $count_confirmed[0] members subscribing to this list."; $notify_confirm = new SMLmailer; $notify_confirm->subject = "$config[list_name] Subscription Confirmation"; $notify_confirm->mail_to = $config['owner_email']; $notify_confirm->message = $admin_note; $notify_confirm->unsub_message = ""; $notify_confirm->use_SMTP = ($config[use_SMTP] == 1) ? true:false; $notify_confirm->send(); } if($config['notify_user_on_confirm']) { $user_note = "Thank you for joining the $config[list_name] list."; $notify_user_confirm = new SMLmailer; $notify_user_confirm->subject = "$config[list_name] Subscription Confirmation"; $notify_user_confirm->mail_to = $email; $notify_user_confirm->message = $user_note; $notify_user_confirm->unsub_message = ""; $notify_user_confirm->use_SMTP = ($config[use_SMTP] == 1) ? true:false; $notify_user_confirm->send(); } } 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 = '$email' AND userkey = '$key'"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); $confirm_message = "Thank you, you have been unsubscribed from $config[list_name]."; if($config['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 $config[list_name]. There are now $count_confirmed[0] members subscribing to this list."; $notify_unsub = new SMLmailer; $notify_unsub->subject = "$config[list_name] Unsubscription"; $notify_unsub->mail_to = $config['owner_email']; $notify_unsub->message = $admin_note; $notify_unsub->unsub_message = ""; $notify_unsub->use_SMTP = ($config[use_SMTP] == 1) ? true:false; $notify_unsub->send(); } if($config['notify_user_on_unsub']) { $user_note = "You have been successfully unsubsribed from the $config[list_name] list."; $notify_user_unsub = new SMLmailer; $notify_user_unsub->subject = "$config[list_name] Unsubscription Confirmation"; $notify_user_unsub->mail_to = $email; $notify_user_unsub->message = $user_note; $notify_user_unsub->unsub_message = ""; $notify_user_unsub->use_SMTP = ($config[use_SMTP] == 1) ? true:false; $notify_user_unsub->send(); } } else { // one of the two denied conditions above occurred. $confirm_message = "Error processing request. Please contact $config[owner_email] for assistance.\n"; } } else { // No record found to confirm or unsubscribe in db $confirm_message = "Error processing request. Please contact $config[owner_email] for assistance.\n"; } echo $confirm_message; } echo <<
All subscribe/unsubscribe requests must be confirmed via email. EOT; ?>