View Single Post
  #1  
Old 01-27-2003, 10:22 AM
 
usermike usermike is offline
 

Advanced Member
  
Join Date: Jan 2003
Posts: 41
 

Default Simple way to check newsletter email addresses

When a user subscribes to the newsletter, in order to prevent people who don't want to be signed up and people who sign other people up, I have coded a way so that the email address be checked before it is added to the newsletter list.

I did this pretty quickly, so if anyone has any improvements, I would be happy to see them Always remember to backup all files before implementing anything in case you miss something.

First, in /customer/home_main.tpl add the following code right after the first if statement:

Code:
{elseif $smarty.get.mode eq "subscribed_ch"} {include file="main/subscribe_confirmation_ch.tpl"}

then make a file called subscribe-ch.php (in the /mail directory) and put the following code in it:

Code:
<? # # $Id: subscribe-ch.php,v 1 2003/1/27 10:59:49 matr Exp $ # require "../smarty.php"; require "../config.php"; require "./func.php"; include "../include/get_language.php"; $email = trim(($email)); if (!is_correct_efunc_send_mail($email)) { header("Location: ../$redirect/error_message.php?subscribe_bad_email"); } else { $result = db_query("select count(*) from $sql_tbl[maillist] where email='$email'"); list($c) = db_fetch_row($result); db_free_result($result); if ($c > 0) { header("Location: ../$redirect/error_message.php?subscribe_exist_email"); } else { //db_query("insert into $sql_tbl[maillist] values('$email', '".time()."')"); # # Send mail notification to customer # $mail_smarty->assign("email",$email); func_send_mail($email, "mail/newsletter_subscribe_subj.tpl", "mail/newsletter_subscribe_ch.tpl", $config["Company"]["newsletter_email"], false); # # Send mail notification to admin # func_send_mail($config["Company"]["newsletter_email"], "mail/newsletter_admin_subj.tpl", "mail/newsletter_admin.tpl", $email, true); header("Location: ../$redirect/home.php?mode=subscribed_ch&email=".urlencode($email)); } } ?>

then add the following template file called subscribe_confirmation_ch.tpl in the skin1/main directory:

Code:
{* $Id: subscribe_confirmation_ch.tpl,v 1 2003/1/27 13:54:57 zorg Exp $ *} { include file="location.tpl" last_location=$lng.lbl_newsletter_subscription} {capture name=dialog} {$lng.txt_newsletter_subscription_msg_ch} {$smarty.get.email} {/capture} { include file="dialog.tpl" title=$lng.txt_thankyou_for_subscribing content=$smarty.capture.dialog extra="width=100%"}

note the creation of: txt_newsletter_subscription_msg_ch. This will be a message such as:

Quote:
Thank you for subscribing. You will receive an email with a URL in it. Please click on that URL to complete your registration to our newsletter.

Then, create newsletter_subscribe_ch.tpl in the skin1/mail directory and include the following code:

Code:
{* $Id: newsletter_subscribe_ch.tpl,v 1 2003/1/27 06:55:21 lucky Exp $ *} {config_load file="$skin_config"} {$lng.lbl_hello} {$lng.eml_tobe_subscribed} {$http_location}mail/subscribe.php?redirect=customer&email={$email|escape} {include file="mail/signature.tpl"}

Note the creation of eml_tobe_subscribed - this will be something that says

Quote:
This email will be subscribed in the newsletter. Please click on the following link to complete registration.

and finally, modify subscribe_confirmation.tpl in the skin1/main directory to have this code:

Code:
{* $Id: subscribe_confirmation.tpl,v 1.11 2002/10/17 13:54:57 zorg Exp $ *} { include file="location.tpl" last_location=$lng.lbl_newsletter_subscription} {capture name=dialog} {$lng.txt_newsletter_subscription_msg}: {$smarty.get.email} {/capture} { include file="dialog.tpl" title=$lng.txt_thankyou_for_subscribing content=$smarty.capture.dialog extra="width=100%"}

Note that I took out the unsubscribe information. This is not necessary anymore.


Let me know how the installation went. I don't think I left out anything
Reply With Quote