Jump to content


Corporate Sponsors


Latest News: (loading..)

tle

Member Since 06 Jul 2009
Offline Last Active Aug 14 2011, 12:40
-----

Topics I've Started

Newsletter Products, getting repeating products when emailed out

05 August 2011, 23:11

Im a real novice when it comes to programming. Could someone check where I could be going wrong with the following loop. I have been trying to resolve the Unsubscribe function as it was not previously picking up the correct email address to unsubscribe customers. Now this is resolved, it has caused another problem. The problem is that when the newsletter is sent out, the products are repeated in each succeeding email. For example, If there are only 4 products..the second subscriber will receive 8 products (the products will repeat itself). You can imagine the result if I send it out to 500 customers.

I think the problem is with the While loop in the function send. I found that if I move the While loop further down the Unsubscribe function no longer works as it does not pick up the correct customer but the repeat products does not occur. Here is the code. Any help is greatly appreciated!

function send($newsletter_id) {

      $mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");

	  //create id for current mailing

	  $messageId = "Message-Id: <" . time() . "@" . $_SERVER['SERVER_NAME'] . ">";
	  

      $mimemessage = new email(array('X-Mailer: osCommerce bulk mailer', $messageId));
      

      //$mimemessage->add_text($this->content);

      //$text = $this->text_content();

      while ($mail = tep_db_fetch_array($mail_query)) {

      $mimemessage->add_html($this->html_content() .'<p align=center><font color="#FFFFFF">' . TEXT_UNSUBSCRIBE . '</font>'. "\n" . '<a href="' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG . FILENAME_UNSUBSCRIBE . "?email=" . $mail['customers_email_address'] . '">' . TEXT_UNSUBSCRIBE2 . '</a></p>' , $this->text_content() . TEXT_UNSUBSCRIBE . "\n" . tep_catalog_href_link(FILENAME_UNSUBSCRIBE . "?email=" . $mail['customers_email_address']));
	  
      $mimemessage->build_message();

      $mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', EMAIL_FROM, $this->title);

      }


      $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) . "'");

    }

  }