开发者

phpmailer column loop & skip NULLs

I am trying to loop through 5 columns in a row to send an email with PHPmailer. Each row can contain up to 5 email addresses but not all do. My loop method works but if a NULL exists where no email address is available, the email does not get sent. How can I get my script to ignore NULLs. Also, is there a better loop process for 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_ti开发者_JAVA技巧mezone_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"); ...


You can solve this by eliminating the NULLs in your MySQL query from the server. Try this MySQL query instead, which should eliminate the NULLs:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜