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 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)