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

时间:2017-03-29 10:30:44

标签: php email phpmailer

我有一个发送大邮件的邮件脚本 在这个邮件中是一个取消订阅按钮,用来填写收件人的mailaddress 但由于某些原因,当邮件发送给收件人A时,来自收件人B的邮件已被填写。

我的剧本片段:

<?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 . "\r\n";
      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'] . "\r\n";
      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包含带变量的邮件模板 取消订阅按钮有一个{EMAIL}变量 正如您在脚本中看到的那样,$ mail [&#39; customers_email_address&#39;]用于AddAddress和{EMAIL}变量。
那么这些价值观是如何相互不同的呢?

1 个答案:

答案 0 :(得分:1)

第一次在$ layout中使用$ mail ['customers_email_address']更改{EMAIL},第二次调用$ layout时,您没有{EMAIL}。 你应该填写$ layout2 = str_replace('{EMAIL}',$ mail ['customers_email_address'],$ layout); 并发送$ sendmail-&gt; MsgHTML($ layout2);

然后原始的$ layout应该保持不变