0

My friend aks me to help him with some issue on his small website. Since some time no one from his subscribers receives his e-mails, except himself and in addition many times (I guess that his address is defined as BBC in send_mail function so inf fact he will receive all e-mails sent from his website?).

Below I am attaching function which is responsible for such feature, made by someone who prepared this website years ago. I am beginner, I tried to solve this issue but without success. I guess it's something with that loop?

        function admin_send_email_news($news_id, $subject, $limit_start = NULL, $limit_offset = NULL){
      // get news
      $row = admin_get_news_for_id($news_id);
      $news_content_short = $row["news_content_short"];
      $news_content = $row["news_content"];
    
      try {
          $result2 = mysql_query("SELECT user_email FROM h_user WHERE blocked_user='false' AND user_consent='true'");
          while ($row2 = mysql_fetch_array($result2)) {
            try {
              send_mail($row2["user_email"], $subject,
                        $news_content_short . $news_content);
            } catch (Exception $e) {}
          }
          if (is_null($limit_start) || is_null($limit_offset)) {
            return false;
          } else {
            return ($count == $limit_offset);
          }
        } catch (Exception $e) {
          error_user("Error while sending message " . $e->getMessage());
        }
        return false;
}
Todra
  • 13
  • 6
  • 1
    There's not much we can do with this tiny snippet of code. Instead of concentrating on problems with the code, you could have a look at the mail server itself. Have a [look at the answers here](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail). – KIKO Software Apr 09 '22 at 16:45
  • **Warning:** `mysql_*` extension is deprecated as of PHP 5.5.0 (2013), and has been removed as of PHP 7.0.0 (2015). Instead, either the [mysqli](https://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](https://www.php.net/manual/en/book.pdo.php) extension should be used. See also the [MySQL API Overview](https://www.php.net/manual/en/mysqlinfo.api.choosing.php) for further help while choosing a MySQL API. – Dharman Apr 09 '22 at 20:51
  • Thank you @KIKOSoftware, I guess mail server is OK, as other messgaes are sent without problem (eg. user registration - both admin and user receives confirmation correctly etc.). The problem occurs only with newsletter... – Todra Apr 11 '22 at 12:21
  • In this case I wouldn't guess, I would make sure. You can do some basic checks on your mail server. A website that can help is: https://internet.nl/test-mail/ It doesn't need to be perfect, but if it's bad you'll know. – KIKO Software Apr 11 '22 at 13:17

0 Answers0