我正在尝试连续遍历5列以发送带有PHPmailer的电子邮件。每行最多可包含5个电子邮件地址,但不是全部。我的循环方法有效但如果存在没有可用电子邮件地址的NULL,则不会发送电子邮件。如何让我的脚本忽略NULL。另外,Columns有更好的循环过程吗?
include("conn.php"); require("class.phpmailer.php"); // require("class.smtp.php"); // require("class.pop3.php"); $conn = mssql_connect($server, $user, $pass) or die("ERROR: Connection to MYSERVER failed"); $select = mssql_select_db($database, $conn) or die("ERROR: Selecting database failed"); $sql1 = "SELECT Email1 as email1, Email2 as email2, Email3 as email3, Email4 as email4, Email5 as email5 FROM $table2 where IPaddress='000.000.000.000'"; $result1 = mssql_query($sql1); while ($row1 = mssql_fetch_assoc($result1)) { $EmailADD1 = $row1["email1"]; $EmailADD2 = $row1["email2"]; $EmailADD3 = $row1["email3"]; $EmailADD4 = $row1["email4"]; $EmailADD5 = $row1["email5"]; //error_reporting(E_ALL); error_reporting(E_STRICT); ini_set('log_errors', 'On'); ini_set('display_errors', 'On'); date_default_timezone_set('America/Toronto'); //include ("class.phpmailer.php"); //include("class.smtp.php"); $mail = new PHPMailer(); $mail->SetLanguage('en', 'C:\PHP\mail\language\\'); $mail->IsSMTP(); // set mailer to use SMTP $mail->Host = "me@me.net"; // specify main and backup server $mail->Port = 25; // set the SMTP port $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "me"; // SMTP username $mail->Password = "xxxxx"; // SMTP password $mail->From = "me@me.net"; $mail->FromName = "Mailer"; //$body = $mail->getFile('contents.html'); //$body = eregi_replace("[\]", '', $body); $mail->AddReplyTo("me@me.com", "JT"); $mail->From = "me@me.net"; //$mail->AddAddress("me@me.com", "JohnTest"); $mail->FromName = "Me"; $mail->Subject = "PHPMailer Test"; $mail->Body = "Hi,
This is the HTML BODY
$IP"; //HTML Body $mail->WordWrap = 50; // set word wrap $mail->AddAddress($EmailADD1, "IPscoreBounceInfo1"); $mail->AddAddress($EmailADD2, "IPscoreBounceInfo2"); $mail->AddAddress($EmailADD3, "IPscoreBounceInfo3"); $mail->AddAddress($EmailADD4, "IPscoreBounceInfo4"); $mail->AddAddress($EmailADD5, "IPscoreBounceInfo5"); ...
答案 0 :(得分:1)
您可以通过从服务器中消除MySQL查询中的NULL来解决此问题。请尝试使用此MySQL查询,这应该消除NULL:
SELECT * FROM (
SELECT Email1 as email FROM $table2 where IPaddress='000.000.000.000'
UNION
SELECT Email2 as email FROM $table2 where IPaddress='000.000.000.000'
UNION
SELECT Email3 as email FROM $table2 where IPaddress='000.000.000.000'
UNION
SELECT Email4 as email FROM $table2 where IPaddress='000.000.000.000'
UNION
SELECT Email5 as email FROM $table2 where IPaddress='000.000.000.000'
) WHERE email IS NOT NULL