douhuan1950 2017-03-29 10:30
浏览 22
已采纳

邮件脚本正在混合邮件收件人

I have a mailing script that is sending a large mailing.
In this mailing is a unsubscribe button witch fills in the mailaddress from the recipients.
But for some reason when a mails goes to recipients A the mailaddress from recipients B is filled in.

A snippet of my script:

<?php
//First get 500 mailaddressess to send the mail to
$sql = mysql_query( "select mail_id, customers_email_address from " . TABLE_NIEUWSBRIEVEN_MAILING_LIST . " where nieuwsbrief_id = '" . mysql_real_escape_string( $nID ) . "' and send = 0 order by mail_id limit " . $aantal_verzenden ) or die ( mysql_error() ); 

while ( $mail = mysql_fetch_array( $sql ) )
{        
    $sendmail = new PHPMailer();
    $sendmail->AddReplyTo( $data['afzender_email'], ucfirst( $data['afzender_naam'] ) );                
    $sendmail->AddAddress( $mail['customers_email_address'] );
    $sendmail->SetFrom( $data['afzender_email'], ucfirst( $data['afzender_naam'] ) );

    // This part is filling in the mailadress at the subscribe button.
    $layout = str_replace( '{EMAIL}', $mail['customers_email_address'], $layout );

    $mbEnc = mb_internal_encoding();
    mb_internal_encoding('UTF-8');
    $sendmail->Subject    = str_replace( '€', mb_encode_mimeheader('€', 'UTF-8'), $data['nieuwsbrief_titel'] );
    mb_internal_encoding($mbEnc);

    $sendmail->AltBody = str_replace( '{ONLINE_WEERGAVE}', 'http://myssite.nl/p-' . $data['url'],  str_replace( '{AFZENDER_ID}', $data['afzenderid'], $data['alt_mail'] ) );
    $sendmail->MsgHTML($layout);

    if(!$sendmail->Send()) {
      echo "Mailer Error: " . $sendmail->ErrorInfo . "
";
      mysql_query( "insert into nieuwsbrief_zender_errors ( email, error ) values ( '" . mysql_real_escape_string( $mail['customers_email_address'] ) . "', '" . mysql_real_escape_string( $sendmail->ErrorInfo ) . "' )" );
      mysql_query( "update " . TABLE_NIEUWSBRIEVEN_MAILING_LIST . " set send = 2 where mail_id = '" . mysql_real_escape_string( $mail['mail_id'] ) . "'"  ) or die ( mysql_error() ); 
    } else {
      echo "Bericht succesvol verzonden!";
      echo $mail['customers_email_address'] . "
";
      mysql_query( "update " . TABLE_NIEUWSBRIEVEN_MAILING_LIST . " set send = 1 where mail_id = '" . mysql_real_escape_string( $mail['mail_id'] ) . "'"  ) or die ( mysql_error() ); 
    }

    $sendmail->ClearAddresses();
    $sendmail->ClearAttachments();

}
?>

$layout is containing the mail template with variables.
The unsubscribe button has a {EMAIL} variable.
As you can see in the script the $mail['customers_email_address'] is used for the AddAddress and for the {EMAIL} variable.
So how is it possible that those values are different from each other?

  • 写回答

1条回答 默认 最新

  • doushi1929 2017-03-29 11:09
    关注

    The first time you change the {EMAIL} with $mail['customers_email_address'] in $layout and when the second time you call $layout you don't have {EMAIL}. You should fill $layout2 = str_replace( '{EMAIL}', $mail['customers_email_address'], $layout ); and send $sendmail->MsgHTML($layout2);

    Then the original $layout should stay the same

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么