PHPMAIL的问题.任何建议


Trouble with PHPMAIL..Any advice?

在脚本中执行select和send到所有电子邮件地址时遇到问题

// Get Employee's Email Address
            $getEmail = "SELECT empEmail AS theEmail FROM employees";
            $emailres = mysqli_query($mysqli, $getEmail) or die('-1'.mysqli_error());
            $col = mysqli_fetch_assoc($emailres);
            $theEmail = $col['theEmail'];           
// the message
            $message = '<html><body>';
            $message .= '<h3>New Site Notifications</h3>';
            $message .= '<p>'.$noticeTitle.'</p>';
            $message .= '<p>'.$noticeText.'</p>';
            $message .= '<p>'.$messageText.'</p>';
            $message .= '<hr>';
            $message .= '<p>'.$emailLoginLink.'</p>';
            $message .= '<p>Thank you<br>Bliss Door Supervisors</p>';
            $message .= '</body></html>';
            $headers = "From: ".$siteName." <".$businessEmail.">'r'n";
            $headers .= "Reply-To: ".$businessEmail."'r'n";
            $headers .= "MIME-Version: 1.0'r'n";
            $headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";

// use wordwrap() if lines are longer than 70 characters
//$msg = wordwrap($msg,70);
// send email
mail($theEmail," New Site Notification",$message,$headers);
//End Send Mail 

由于某种原因,它只发送数据库中的第一封电子邮件,而不发送数据库中的其他10多封电子邮件。有人知道我哪里出错了吗?或帮助。

多谢高峰

Fetch一次只提取一行。将fetch移动到循环中,如…

// Get Employee's Email Address
            $getEmail = "SELECT empEmail AS theEmail FROM employees";
            $emailres = mysqli_query($mysqli, $getEmail) or die('-1'.mysqli_error());
            while($col = mysqli_fetch_assoc($emailres)){ //start loop here so each email address is pulled
                 $theEmail = $col['theEmail'];           
// the message
                 $message = '<html><body>';
                 $message .= '<h3>New Site Notifications</h3>';
                 $message .= '<p>'.$noticeTitle.'</p>';
                 $message .= '<p>'.$noticeText.'</p>';
                 $message .= '<p>'.$messageText.'</p>';
                 $message .= '<hr>';
                 $message .= '<p>'.$emailLoginLink.'</p>';
                 $message .= '<p>Thank you<br>Bliss Door Supervisors</p>';
                 $message .= '</body></html>';
                 $headers = "From: ".$siteName." <".$businessEmail.">'r'n";
                 $headers .= "Reply-To: ".$businessEmail."'r'n";
                 $headers .= "MIME-Version: 1.0'r'n";
                 $headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";

     // use wordwrap() if lines are longer than 70 characters
     //$msg = wordwrap($msg,70);
     // send email
     mail($theEmail," New Site Notification",$message,$headers);
     //End Send Mail
}//end loop

参考:http://php.net/manual/en/mysqli-result.fetch-assoc.php

返回与获取的行

对应的关联数组。

从他们的例子:

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = $mysqli->query($query)) {
    /* fetch associative array */
    while ($row = $result->fetch_assoc()) {
        printf ("%s (%s)'n", $row["Name"], $row["CountryCode"]);
    }