PHP 循环电子邮件读取数组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 循环电子邮件读取数组相关的知识,希望对你有一定的参考价值。

<?php

  set_time_limit(0); // this will keep the script from stopping if it takes longer then 30 seconds, must have this here
  $emailaddress = array('test1@test.com', 'test2@test.com', 'test3@test.com', 'test4@test.com', 'test5@test.com', 'test6@test.com');
  $emailsubject = "This is a sample subject!";
  $emailbody = file_get_contents("email.html");
  $fromaddress = "name@domain.tld";
  $i = count($emailaddress);
  $z = 0;
  
  // here we check how many  email address's we have, if its is 0, then we don't start the email function
  if ($i != 0)
    {// start if
      
      // Lets loop until we reach the count from email address array
      while ($i != $z)
        {// start while
          
          // here we send the email to the varables from above, using the email array incrament
          mail($emailaddress[$z], $emailsubject, $emailbody, "From: " .$fromaddress. "\nX-Mailer: PHP 4.x");
          
          // lets echo out that the email was sent
          echo $z + 1 . " out of " . $i . " emails sent. (" . $emailaddress[$z] . ")<br>";
          
          // increment the array one, so we get a new email address from the array
		  ++$z;
		  
        }// end while   
		
      }//end if
      
   else
     {//start else
       
       // we echo out that no emails where found in the array and end the script
       echo "Warning: No emails in array.";
	   	 
     }// end else
	 
?>

以上是关于PHP 循环电子邮件读取数组的主要内容,如果未能解决你的问题,请参考以下文章

循环读取 PHP 数组输出

PHP中使用foreach循环读取数组数据的方法

PHP中使用foreach循环读取数组数据的方法

循环电子邮件读取平面文件

[单选题]要循环操作非顺序索引的数组时,可以用下面哪个函数来读取数组当面元素的索引值?

sql 读取数组问题