Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

Newsletter Unsubscribe


2 replies to this topic

#1 Zahoor

  • Community Member
  • 23 posts
  • Real Name:ZA
  • Gender:Male
  • Location:Norway

Posted 14 November 2007, 01:11

I am using this contribution together with this contribution: simple visitor newsletter v2.1

What I want help with is that I also want the visitors who have subscribed to be able to unsubscribe. I have made following changes to function send($newsletter_id) in admin/newsletter.php:

  function send($newsletter_id) {
	 $mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");
	 $visitor_query = tep_db_query("select email from " . TABLE_VISITOR);

   $mimemessage = new email(array('X-Mailer: osC mailer'));
  

   // Build the text version
   $text = strip_tags($text);
   if (EMAIL_USE_HTML == 'true') {
	 $mimemessage->add_html($this->content);
   } else {
	 $mimemessage->add_text($this->content);
   }
  while ($mail = tep_db_fetch_array($mail_query)) {
   $mimemessage->add_html($this->content . TEXT_UNSUBSCRIBE . '<a href="' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG . FILENAME_UNSUBSCRIBE . "?email=" . $mail['customers_email_address'] . '">' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG . FILENAME_UNSUBSCRIBE . "?email=" . $mail['customers_email_address'] . '</a>'); 
   $mimemessage->build_message();
   $mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', EMAIL_FROM, $this->title);
 }
/////Simple Visitor Newsletter
   while ($visitor = tep_db_fetch_array($visitor_query)) {
   $mimemessage->add_html($this->content . TEXT_UNSUBSCRIBE . '<a href="' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG . FILENAME_UNSUBSCRIBE . "?email=" . $visitor['email'] . '">' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG . FILENAME_UNSUBSCRIBE . "?email=" . $visitor['email'] . '</a>'); 
   $mimemessage->build_message();
   $mimemessage->send('Besøkende - ' . ' ' . 'Fridas Barnebutikk', $visitor['email'], '', EMAIL_FROM, $this->title);
 }
/////Simple Visitor Newsletter
	 $newsletter_id = tep_db_prepare_input($newsletter_id);
	 tep_db_query("update " . TABLE_NEWSLETTERS . " set date_sent = now(), status = '1' where newsletters_id = '" . tep_db_input($newsletter_id) . "'");
   }
 }

and tried this in unsubscribe_done.php:

 <?php
			// If we found the customers email address, and they currently subscribe
			if ($cus_subscribe) {
			  // Unsubscribe them
			  tep_db_query("update " . TABLE_CUSTOMERS . " set customers_newsletter = '0' where customers_email_address = '" . $email_to_unsubscribe . "'");
		   } else if ($vis_subscribe) {
		   // Unsubscribe visitor
		   tep_db_query("delete from " . TABLE_VISITOR . " where convert ('" . TABLE_VISITOR . "''"."''"email"' using utf8) = '" . $email_to_unsubscribe . "'");
			?>
			 <td class="main"><?php echo UNSUBSCRIBE_DONE_TEXT_INFORMATION . $email_to_unsubscribe; ?></td>
		   <?php 
			 // Otherwise, we want to display an error message (This should never occur, unless they try to unsubscribe twice)
			 } else {
		   ?>
			   <td class="main"><?php echo UNSUBSCRIBE_ERROR_INFORMATION . $email_to_unsubscribe; ?></td>
		   <?php
			 }
		   ?>

But I am getting following error:

Parse error: syntax error, unexpected T_STRING in unsubscribe_done.php on line 76

Line 76 is quoted below:

tep_db_query("delete from " . TABLE_VISITOR . " where convert ('" . TABLE_VISITOR . "''"."''"email"' using utf8) = '" . $email_to_unsubscribe . "'");

Could someone please correct this query for me, as I can't find out whats wrong and where? Please advice

#2 Zahoor

  • Community Member
  • 23 posts
  • Real Name:ZA
  • Gender:Male
  • Location:Norway

Posted 14 November 2007, 23:09

I found the problem and have fixed it now!

#3 Zahoor

  • Community Member
  • 23 posts
  • Real Name:ZA
  • Gender:Male
  • Location:Norway

Posted 16 March 2011, 20:53

For the benefit of other who might get stuck this is what was done:

Place this code right under "require('includes/application_top.php');" in unsubscribe_done.php

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_UNSUBSCRIBE);
    if (isset($HTTP_GET_VARS['email'])) {
      $email_to_unsubscribe = ereg_replace('[^0-9A-Za-z@._-]', '', $HTTP_GET_VARS['email']); 
    } else {
      $email_to_unsubscribe = '';
    }

Then place the following code right under " $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_UNSUBSCRIBE, '', 'NONSSL'));" in the same file, unsubscribe_done.php

// Check and see if the email exists in the database, and is subscribed to the newsletter.
  $cus_subscribe_raw = "select 1 from " . TABLE_CUSTOMERS . " where customers_newsletter = '1' and customers_email_address = '" . $email_to_unsubscribe . "'";
  $cus_subscribe_query = tep_db_query($cus_subscribe_raw);
  
  $cus_subscribe = tep_db_fetch_array($cus_subscribe_query);

// We know that visitor is allready subscirbed
  $vis_subscribe_raw = "select 1 from " . TABLE_VISITOR . " where email = '" . $email_to_unsubscribe . "'";
  $vis_subscribe_query = tep_db_query($vis_subscribe_raw);
  $vis_subscribe = tep_db_fetch_array($vis_subscribe_query);

Last you need to place this code at a proper place in the same file as above:

<?php
            // If we found the customers email address, and they currently subscribe
            if ($cus_subscribe) {
              // Unsubscribe customer
              tep_db_query("update " . TABLE_CUSTOMERS . " set customers_newsletter = '0' where customers_email_address = '" . $email_to_unsubscribe . "'");
			  ?>
			<td class="main"><?php echo UNSUBSCRIBE_DONE_TEXT_INFORMATION . $email_to_unsubscribe; ?></td>
			<?php
           } else if ($vis_subscribe) {
		   // Unsubscribe visitor
		   tep_db_query("delete from " . TABLE_VISITOR . " where email = '" . $email_to_unsubscribe . "'");
		    ?>
             <td class="smallText"><?php echo UNSUBSCRIBE_DONE_TEXT_INFORMATION . $email_to_unsubscribe; ?></td>
           <?php 
             // Otherwise, we want to display an error message (This should never occur, unless they try to unsubscribe twice)
             } else {
           ?>
               <td class="main"><?php echo UNSUBSCRIBE_ERROR_INFORMATION . $email_to_unsubscribe; ?></td>
           <?php
             }
           ?>