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?