206 lines
5.5 KiB
PHP
206 lines
5.5 KiB
PHP
<?php
|
||
set_time_limit(0);
|
||
require("config.php");
|
||
|
||
if($_GET['email_test'])
|
||
{
|
||
$sql="SELECT * FROM settings";
|
||
$rez=mysql_query($sql,$rc);
|
||
$settings=mysql_fetch_assoc($rez);
|
||
$f1=file("http://f-rent.com/mail/templates/".$settings['email_template']);
|
||
$text = implode("",$f1);
|
||
$text = str_replace("[%email%]",$emails[$i],$text);
|
||
$r = send_email($_GET['email_test'], $settings['theme'], $text, true);
|
||
if($r==1) $msg = "<font color=green>Сообщение на почту <strong>$_GET[email_test]</strong> успешно отправлено!<br></font>";
|
||
else $msg = "<font color=red>Не удалось отправить сообщение на почту <s>$_GET[email_test]</s><br>$r</font>";
|
||
$msg = urlencode($msg);
|
||
if(!$_GET['dev']) echo "<script>location.replace('http://f-rent.com/admin/subscribe.php?suc=$msg');</script>";
|
||
} else
|
||
{
|
||
$sql2="SELECT * FROM settings";
|
||
$rez2=mysql_query($sql2,$rc);
|
||
$settings=mysql_fetch_assoc($rez2);
|
||
|
||
if($settings['email_from'] != "robot@joywork.ru") die();
|
||
|
||
$sql = "SELECT * FROM subscribe WHERE active = 1 AND active_try <= 3 ORDER BY RAND() LIMIT 0,50";
|
||
$rez = mysql_query($sql,$rc);
|
||
if(mysql_num_rows($rez))
|
||
{
|
||
$f1=file("http://f-rent.com/mail/templates/".$settings['email_template']);
|
||
$text = implode("",$f1);
|
||
while($mt = mysql_fetch_assoc($rez))
|
||
{
|
||
$sendText = $text.'<table width="100%" cellspacing="0" cellpadding="0" align="center"><tr><td><a href="https://joywork.ru/mailer/unsubscribe.php?email='.urlencode($mt['email']).'">Отписаться от рассылки</a></td></tr></table>';
|
||
$r = send_email($mt['email'],$settings['theme'],$sendText,true);
|
||
if($r == 1)
|
||
{
|
||
$sql = "UPDATE subscribe SET active = 0, active_try = active_try + 1, try = try + 1, date_otpr = NOW() WHERE id = $mt[id]";
|
||
mysql_query($sql);
|
||
} else
|
||
{
|
||
$prim = "$mt[prim] Попытка №$mt[active_try] (".date("d.m H:i").") $r <br>";
|
||
$sql = "UPDATE subscribe SET active_try = active_try + 1, try = try + 1, date_otpr = NOW(), prim = '$prim' WHERE id = $mt[id]";
|
||
mysql_query($sql);
|
||
}
|
||
}
|
||
} else echo "no mails";
|
||
}
|
||
|
||
function send_email($address, $subject, $body, $test=false, $from=false, $fromname=false) {
|
||
|
||
exit;
|
||
|
||
require_once("mailer/PHPMailerAutoload.php");
|
||
$sql="SELECT * FROM settings";
|
||
$rez=mysql_query($sql);
|
||
$settings=mysql_fetch_array($rez);
|
||
|
||
$mail = new PHPMailer();
|
||
|
||
if($_GET['dev']) $mail->SMTPDebug = 3;
|
||
$mail->IsSMTP();
|
||
$mail->Host = "smtp.mailganer.com";
|
||
$mail->Port = 1126;
|
||
$mail->SMTPAuth = true;
|
||
$mail->Username = "290";
|
||
$mail->Password = "MGYzVAVmlKVG1nVW5BK05MVnVtKnN3eUg7cUVlPSRucVF2PEJhUFpEcXpCTGo+RHU7JD0kZDpqWEBhPTg7I2E=";
|
||
$mail->isHTML(true);
|
||
$mail->ConfirmReadingTo = "robot@joywork.ru";
|
||
$mail->AddCustomHeader('Precedence: bulk;');
|
||
$mail->AddCustomHeader('List-Unsubscribe: https://joywork.ru/mailer/unsubscribe.php;');
|
||
$mail->AddCustomHeader('List-id: Subscribe <'.translit($theme).'>');
|
||
$mail->AddCustomHeader('X-Mailru-Msgtype: '.md5('robot@joywork.ru').';');
|
||
$mail->AddCustomHeader('X-Postmaster-Msgtype: '.md5('robot@joywork.ru').';');
|
||
$mail->AddCustomHeader('Date: '.date("D, d M y H:i:s O").';');
|
||
|
||
$mail->SMTPOptions = array(
|
||
'ssl' => array(
|
||
'verify_peer' => false,
|
||
'verify_peer_name' => false,
|
||
'allow_self_signed' => true
|
||
)
|
||
);
|
||
|
||
if(!$from) $from = $settings['email_from'];
|
||
if(!$fromname) $fromname = $settings['from'];
|
||
$mail->From = $from;
|
||
$mail->FromName = $fromname;
|
||
|
||
$mail->CharSet = "utf-8";
|
||
$mail->addAddress($address);
|
||
$mail->Subject = $subject;
|
||
$mail->Body = $body;
|
||
$mail->AltBody = "Это письмо сгенерировано в формате HTML. Ваш клиент не поддерживает HTML или эта функция выключена.";
|
||
|
||
if($test)
|
||
if($mail->Send()) return true; else return $mail->ErrorInfo;
|
||
else if($mail->Send()) return true; else return false;
|
||
}
|
||
|
||
function translit($insert)
|
||
{
|
||
$replase = array(
|
||
// Буквы
|
||
'а'=>'a',
|
||
'б'=>'b',
|
||
'в'=>'v',
|
||
'г'=>'g',
|
||
'д'=>'d',
|
||
'е'=>'e',
|
||
'ё'=>'yo',
|
||
'ж'=>'zh',
|
||
'з'=>'z',
|
||
'и'=>'i',
|
||
'й'=>'j',
|
||
'к'=>'k',
|
||
'л'=>'l',
|
||
'м'=>'m',
|
||
'н'=>'n',
|
||
'о'=>'o',
|
||
'п'=>'p',
|
||
'р'=>'r',
|
||
'с'=>'s',
|
||
'т'=>'t',
|
||
'у'=>'u',
|
||
'ф'=>'f',
|
||
'х'=>'h',
|
||
'ц'=>'c',
|
||
'ч'=>'ch',
|
||
'ш'=>'sh',
|
||
'щ'=>'shh',
|
||
'ъ'=>'j',
|
||
'ы'=>'y',
|
||
'ь'=>'',
|
||
'э'=>'e',
|
||
'ю'=>'yu',
|
||
'я'=>'ya',
|
||
'А'=>'a',
|
||
'Б'=>'b',
|
||
'В'=>'v',
|
||
'Г'=>'g',
|
||
'Д'=>'d',
|
||
'Е'=>'e',
|
||
'Ё'=>'yo',
|
||
'Ж'=>'zh',
|
||
'З'=>'z',
|
||
'И'=>'i',
|
||
'Й'=>'j',
|
||
'К'=>'k',
|
||
'Л'=>'l',
|
||
'М'=>'m',
|
||
'Н'=>'n',
|
||
'О'=>'o',
|
||
'П'=>'p',
|
||
'Р'=>'r',
|
||
'С'=>'s',
|
||
'Т'=>'t',
|
||
'У'=>'u',
|
||
'Ф'=>'f',
|
||
'Х'=>'h',
|
||
'Ц'=>'c',
|
||
'Ч'=>'ch',
|
||
'Ш'=>'sh',
|
||
'Щ'=>'shh',
|
||
'Ъ'=>'j',
|
||
'Ы'=>'y',
|
||
'Ь'=>'',
|
||
'Э'=>'e',
|
||
'Ю'=>'yu',
|
||
'Я'=>'ya',
|
||
// Всякие знаки препинания и пробелы
|
||
' '=>'-',
|
||
' - '=>'-',
|
||
'_'=>'-',
|
||
//Удаляем
|
||
'.'=>'',
|
||
':'=>'',
|
||
'quot;'=>'',
|
||
'amp;'=>'',
|
||
';'=>'',
|
||
','=>'',
|
||
'!'=>'',
|
||
'?'=>'',
|
||
'>'=>'',
|
||
'<'=>'',
|
||
'&'=>'',
|
||
'*'=>'',
|
||
'%'=>'',
|
||
'$'=>'',
|
||
'"'=>'',
|
||
'\''=>'',
|
||
'('=>'',
|
||
')'=>'',
|
||
'`'=>'',
|
||
'+'=>'',
|
||
'/'=>'',
|
||
'\\'=>'',
|
||
'#'=>'',
|
||
'№'=>'',
|
||
);
|
||
$insert=preg_replace("/ +/"," ",$insert); // Удаляем лишние пробелы
|
||
$insert = strtr($insert,$replase);
|
||
return mb_strtolower($insert);
|
||
}
|
||
|
||
?>
|