Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Newsletter Products, getting repeating products when emailed out


tle

Recommended Posts

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

   }

 }

Link to comment
Share on other sites

The problem is that in the loop you just keep adding to the message.

 

Try changing this code:

 

      $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); 
     } 

To:

 

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

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

     while ($mail = tep_db_fetch_array($mail_query)) { 
       $mimemessage = new email(array('X-Mailer: osCommerce bulk mailer', $messageId)); 

       $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); 

       unset($mimemessage);
     } 

The new code builds the message, sends it, then "destroys" it with each pass thru the loop.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

The problem is that in the loop you just keep adding to the message.

 

Try changing this code:

 

      $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); 
     } 

To:

 

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

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

     while ($mail = tep_db_fetch_array($mail_query)) { 
       $mimemessage = new email(array('X-Mailer: osCommerce bulk mailer', $messageId)); 

       $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); 

       unset($mimemessage);
     } 

The new code builds the message, sends it, then "destroys" it with each pass thru the loop.

 

Hi Jim..

 

Thanks for your help! I have tried your suggested code, though it does not seem to work. It has the same problem, a repetition of products in each succeeding email. I am really stuck! Any other suggestions?

 

Thankyou again.

Link to comment
Share on other sites

I can move the while loop to the following to solve the problem...but it creates another problem. I wont be able to create a link for each individual customer to unsubscribe.

 

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_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(); 

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

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

   }

 }

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...