<?php
// кодировка переданных данных
$data_charset = 'windows-1251';
// кодировка письма
$send_charset = 'KOI8-R';
require("functions/functions.php");
connect_to_database();
mysql_query("SET NAMES CP1251");
mysql_query("SET COLLATION_CONNECTION=CP1251_GENERAL_CI");
$select_all_users = "SELECT email, username, distributor_id from Users where date_added='".date("Y-m-d",time()-7*24*60*60)."' and email NOT in (Select payer_email from Orders)";
$result_all_users = mysql_query($select_all_users);
echo mysql_num_rows($result_all_users)."<BR>\n";
for ($i=0;$i<mysql_num_rows($result_all_users);$i++)
{
$user_row=mysql_fetch_array($result_all_users);
echo $user_row["email"]."<BR>\n";
// multiple recipients
$to = $user_row["email"];
$name_to = $user_row["username"];
// subject
$subject = 'Subject';
$url_special="www.affiliate_website.com";
// message
$message = "Text
<a href=\"".$url_special."\" target=\"_blank\">".$url_special."</a>";
$message = "<html>
<head>
<title>".$subject."</title>
</head>
<body>
<p>".str_replace(chr(13).chr(10), '<BR>',$message)."
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
Если вы больше не хотите получать наши письма - достаточно кликнуть на сюда на \"<a href=\"unsubscribe" target=\"_blank\" name=\"unsubscribe\" title=\"Unsubscribe\">unsubscribe now</a>\".
</body>
</html>";
//$message = substr_replace("\n","<BR>",$message);
//$message = substr_replace("\r","<BR>",$message);
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset='.$data_charset . "\r\n";
// Additional headers
$headers .= 'To: '.mime_header_encode($name_to, $data_charset, $send_charset).'<'.$to.'>' . "\r\n";
$headers .= 'From: '.mime_header_encode("Name", $data_charset, $send_charset).' <EMAIL>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
}
?>