How to send e-mail to multiple recipients from database query (PHP)

前端 未结 7 2412
南方客
南方客 2020-12-29 16:41

I\'m trying to send an e-mail to multiple e-mail address in my database. Here is my current code. It is only working when I specify a single e-mail address, however, I need

相关标签:
7条回答
  • 2020-12-29 17:16

    Use this code to resolve your problem.

      //Connect to database
      mysql_connect("localhost","user","password") or die(mysql_error());
      mysql_select_db("db") or die(mysql_error()); 
      $sql = "SELECT email FROM members";  
      $res = mysql_query($sql) or die(mysql_error());
      while($row = mysql_fetch_assoc($res) )   
      {  
          $area .= $row['email']. ", ";
      }
    
      // read the list of emails from the file.
      $email_list = explode(',', $area);
    
      // count how many emails there are.
      $total_emails = count($email_list);
    
      // go through the list and trim off the newline character.
      for ($counter=0; $counter<$total_emails; $counter++)
      {
          $email_list[$counter] = trim($email_list[$counter]);
      }
      $to = $email_list;
      echo $to;
    
    0 讨论(0)
提交回复
热议问题