Я использую phpmailer для рассылки информационных бюллетеней некоторым подписчикам. Каждый подписчик является частью «Категории». Перед отправкой я сначала выбираю категорию, к которой принадлежат подписчики. У каждого пользователя есть уникальный идентификатор $recipients_id
. Что происходит: в приведенном ниже коде каждый пользователь получает все «ссылки для отказа от описания»; то же самое и с другими членами. И он должен получать отказ от подписки только со своим идентификатором:
// part of the script
$mail->IsHTML(true); //Sets message type to HTML
$mail->Subject = "Newsletter"; //Sets the Subject of the message
$mail->Body = $_POST["message"];
foreach($category_matches as $file) { // grab subscribers of the category
// get data out of txt file
$lines = file($file, FILE_IGNORE_NEW_LINES); // set lines from matched file into an array
$recipients_id = $lines[0]; // id of recipients
$recipients_name = $lines[2]; // name of recipients
$recipients_email = $lines[3]; // email of the recipients
$mail->AddBCC($recipients_email, $recipients_name); //bcc to all subscribers of the category
$mail->Body .= '<a href="http://example.com/newsletter/unsubscribe.php?id='.$recipients_id.'">Unsubscribe</a>'; //unsubscribe anchor
echo $recipients_id.'<br />'; // this echos me the id's of the subscribers in the category to check only
}
if($mail->Send()) //Send an Email. Return true on success or false on error
{
$result = '<div class="alert alert-success">Newsletter sent to subscribers of:<b> '.$recipients_category.'</b></div>';
}
else
{
$result = 'div class="alert alert-danger">There is an Error</div>';
}