phpmailer 列循环和跳过 NULL
Posted
技术标签:
【中文标题】phpmailer 列循环和跳过 NULL【英文标题】:phpmailer column loop & skip NULLs 【发布时间】:2011-09-05 19:49:46 【问题描述】:我正在尝试连续遍历 5 列以使用 phpmailer 发送电子邮件。每行最多可以包含 5 个电子邮件地址,但并非全部都包含。我的循环方法有效,但如果在没有可用电子邮件地址的情况下存在 NULL,则不会发送电子邮件。如何让我的脚本忽略 NULL。另外,Columns有没有更好的循环流程?
包括(“conn.php”); 要求(“class.phpmailer.php”); // 需要("class.smtp.php"); // 需要("class.pop3.php"); $conn = mssql_connect($server, $user, $pass) or die("ERROR: Connection to MYSERVER failed"); $select = mssql_select_db($database, $conn) or die("错误:选择数据库失败"); $sql1 = "选择 Email1 作为 email1,Email2 作为 email2,Email3 作为 email3,Email4 作为 email4,Email5 作为 email5 FROM $table2 where IPaddress='000.000.000.000'"; $result1 = mssql_query($sql1); 而 ($row1 = mssql_fetch_assoc($result1)) $EmailADD1 = $row1["email1"]; $EmailADD2 = $row1["email2"]; $EmailADD3 = $row1["email3"]; $EmailADD4 = $row1["email4"]; $EmailADD5 = $row1["email5"]; //error_reporting(E_ALL); 错误报告(E_STRICT); ini_set('log_errors', '开'); ini_set('display_errors', '开'); date_default_timezone_set('美国/多伦多'); //include ("class.phpmailer.php"); //include("class.smtp.php"); $mail = 新 PHPMailer(); $mail->SetLanguage('en', 'C:\PHP\mail\language\\'); $mail->IsSMTP(); // 设置邮件程序使用 SMTP $mail->Host = "me@me.net"; // 指定主备服务器 $mail->端口 = 25; // 设置 SMTP 端口 $mail->SMTPAuth = 真; // 开启 SMTP 认证 $mail->用户名 = "我"; // SMTP 用户名 $mail->密码 = "xxxxx"; // SMTP 密码 $mail->发件人 = "me@me.net"; $mail->FromName = "Mailer"; //$body = $mail->getFile('contents.html'); //$body = eregi_replace("[\]", '', $body); $mail->AddReplyTo("me@me.com", "JT"); $mail->发件人 = "me@me.net"; //$mail->AddAddress("me@me.com", "JohnTest"); $mail->FromName = "我"; $mail->Subject = "PHPMailer 测试"; $mail->Body = "嗨,这是 HTML 正文$IP"; //HTML正文 $mail->WordWrap = 50; // 设置自动换行 $mail->AddAddress($EmailADD1, "IPscoreBounceInfo1"); $mail->AddAddress($EmailADD2, "IPscoreBounceInfo2"); $mail->AddAddress($EmailADD3, "IPscoreBounceInfo3"); $mail->AddAddress($EmailADD4, "IPscoreBounceInfo4"); $mail->AddAddress($EmailADD5, "IPscoreBounceInfo5"); ...【问题讨论】:
【参考方案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
【讨论】:
感谢landoncz,这行得通……稍作修改。 SELECT Email1 as email FROM IPreputation where IPaddress='000.000.000.000' and Email1 IS NOT NULL UNION SELECT Email2 as email FROM IPreputation where IPaddress='000.000.000.000' and Email2 IS NOT NULL UNION SELECT Email3 as email FROM IPreputation where IPaddress=' 000.000.000.000' and Email3 IS NOT NULL UNION SELECT Email4 as email FROM IPreputation where IPaddress='000.000.000.000' and Email4 IS NOT NULL UNION SELECT Email5 as email FROM IPreputation where IPaddress='000.000.000.000' and Email5 IS NOT NULL以上是关于phpmailer 列循环和跳过 NULL的主要内容,如果未能解决你的问题,请参考以下文章