} elseif (zen_validate_email($email_address) == false) {
$error = true;
$messageStack->add('subscribe', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
} else {
// check if email address exists in CUSTOMERS table or in SUBSCRIBERS table
$check_cust_email_query = "select count(*) as total from " . TABLE_CUSTOMERS .
" where customers_email_address = '" . zen_db_input($email_address) . "'";
$check_cust_email = $db->Execute($check_cust_email_query);
$check_news_email_query = "select count(*) as total from " . TABLE_SUBSCRIBERS .
" where email_address = '" . zen_db_input($email_address) . "'";
$check_news_email = $db->Execute($check_news_email_query);
if ($check_cust_email->fields['total'] > 0) {
$error = true;
$messageStack->add('subscribe', SUBSCRIBE_DUPLICATE_CUSTOMERS_ERROR);
} elseif ($check_news_email->fields['total'] > 0) {
$error = true;
$messageStack->add('subscribe', SUBSCRIBE_DUPLICATE_NEWSONLY_ERROR);
} else {
// we generate a random confirmation code so we can use it as an
// extra security measure to prevent spoofs/scams.
$confirm_code = substr(base64_encode(crypt(str_shuffle(time()))),4,6);
$db->Execute('insert into ' . TABLE_SUBSCRIBERS .
' (email_address, email_format, subscribed_date, confirmed) ' .
"VALUES ('".$email_address."', '".$email_format."', now(), '".$confirm_code."')"
);
// Send confirmation request.
// get the proper uri
$confirm_uri = zen_href_link(FILENAME_SUBSCRIBE_CONFIRM, 'confirm='.$confirm_code.'&email=' . $email_address, 'NONSSL');
// initial welcome
$email_text .= EMAIL_WELCOME;
$html_msg['EMAIL_WELCOME'] = str_replace('\n','',EMAIL_WELCOME);
// add in regular email welcome text
$email_text .= "\n\n" . EMAIL_TEXT . sprintf(EMAIL_CONFIRMATION_TEXT, $confirm_uri ). EMAIL_CONTACT . EMAIL_CLOSURE;
$html_msg['EMAIL_MESSAGE_HTML'] = str_replace('\n','',EMAIL_TEXT );
$html_msg['EMAIL_CONFIRMATION_LINK'] = str_replace('\n','', sprintf(EMAIL_CONFIRMATION_TEXT, '<a href="'.$confirm_uri.'">'.$confirm_uri.'</a>' ));
$html_msg['EMAIL_CONTACT_OWNER'] = str_replace('\n','',EMAIL_CONTACT);
$html_msg['EMAIL_CLOSURE'] = nl2br(EMAIL_CLOSURE);
// include create-account-specific disclaimer
$email_text .= "\n\n" . sprintf(EMAIL_DISCLAIMER_NEW_CUSTOMER, STORE_OWNER_EMAIL_ADDRESS). "\n\n";
$html_msg['EMAIL_DISCLAIMER'] = sprintf(EMAIL_DISCLAIMER_NEW_CUSTOMER, '<a href="mailto:' . STORE_OWNER_EMAIL_ADDRESS . '">'. STORE_OWNER_EMAIL_ADDRESS .' </a>');
// send welcome email
zen_mail($name, $email_address, EMAIL_SUBJECT, $email_text, STORE_NAME, EMAIL_FROM, $html_msg, 'newsletter_subscription');
}
}
}
$breadcrumb->add(NAVBAR_TITLE);
?>