phpmailer列循环并跳过NULL

问题描述

| 我试图连续遍历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)或die(\“错误:与MYSERVER的连接失败\”);     $ select = mssql_select_db($ database,$ conn)或die(\“错误:选择数据库失败\”);     $ sql1 = \“选择电子邮件1作为电子邮件1,电子邮件2作为电子邮件2,电子邮件3作为电子邮件3,电子邮件4作为电子邮件4,电子邮件5作为电子邮件5 FROM $ table2,其中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);     error_reporting(E_STRICT);     ini_set(\'log_errors \',\'开\');     ini_set(\'display_errors \',\'On \');     date_default_timezone_set(\'America / Toronto \');     // 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-> Port = 25; //设置SMTP端口     $ mail-> SMTPAuth = true; //打开SMTP身份验证     $ mail-> Username = \“ me \”; // SMTP用户名     $ mail-> Password = \“ xxxxx \”; // SMTP密码     $ 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 = \“嗨,这是HTML BODY $ 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 \”);     ...     

解决方法

        您可以通过从服务器中消除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