doudou1438 2016-04-26 09:21
浏览 132


I got an issue with phpMailer and it is not sending to multiple addresses when using an if statement. If I hardcode the emails they work fine...

P.s. I have also checked the variables and the if statements and all are working correctly.

$mail = new PHPMailer;

$mail->setFrom('', 'xxx');
if ( $row['recipient2'] != '' ) { $mail->addAddress($row['recipient2']); }
if ( $row['recipient3'] != '' ) { $mail->addAddress($row['recipient3']); }
$mail->addReplyTo('', 'xxx');

EDIT - NEW examples - bounty set:

I tried the following script which should give me 7 addresses however I only get one. (The hardcoded one)

$mail = new PHPMailer;



if ( $rows != 0 ) {
    for ( $i = 0; $i < $rows; $i ++ ) {
        $row = clean_fetch_assoc($result);



Which returns...

int 6

array (size=1)
  '' => boolean true

boolean false

As you can see $rows returns 6 so there is nothing wrong with the loop.

Any ideas?

  • 写回答

4条回答 默认 最新

  • duanjuduo4573 2016-05-18 02:26

    There is not enought code shown to exactly and positively nail down your problem.

    But your $row strongly suggests that you're in the middle of a while($row=$stmt->fetch()), right? We don't see anything like it in the code you show.

    I think I have 99% chances to be right on this.
    Your fix is to "extract" your database data BEFORE the PHPMailer part.

    Get all your vars (Sender, From, FromName and an array of adresses... An array of BCC too? ).

    Finish your while fetch loop BEFORE getting in the PHPMailer part, which shall not be included in a loop.

    THEN, you can go on with your email construction.
    Set your Body, AltBody and Subject.
    Now is the time to loop into an address array.
    (And don't call it $row!!).

    By the way, your for loop declaration isn't as correct as you think:
    ( $i=0;$i<$rows;$i++ ) should be ( $i=0;$i<sizeOf($rows);$i++ ).
    Notice the sizeOf()?

    This code that worked perfect for me:
    I suggest you try it in order to get a confimation that PHPMailer isn't the problem.

    // This array would be defined by you fetch loop.
    $endpointMsg->AddAddress( $clientLine['email'] );
        $endpointMsg->AddAddress( $row[$i] );
    $endpointMsg->AddBCC ($SENDER);

    I've had 5 times the same email with this (adresses were different than - Doh!).
    PHPMailer works like a charm.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 django5安装失败
  • ¥60 ios系统storm sniffer 写入http规则加密如何破解?
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥15 ANSYS分析简单钎焊问题
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开
  • ¥15 在centos7安装conda
  • ¥15 c#调用yolo3 dll文件获取的数据对不上
  • ¥20 WPF 如何实现多语言,label 和cs(live Charts)中是否都能翻译