SqlRow("SELECT * FROM $table_global_config");
(count($row_config_globale) > 0) ? $r = 'SUCCESS' : $r = '';
if ($r != 'SUCCESS') {
include("include/lang/english.php");
echo "
" . tr($r) . "
";
echo "
";
exit;
}
if (empty($row_config_globale['language']))
$row_config_globale['language'] = "english";
include("include/lang/" . $row_config_globale['language'] . ".php");
require('include/lib/PHPMailerAutoload.php');
$step = (empty($_GET['step']) ? "" : $_GET['step']);
$subject = (!empty($_SESSION['subject'])) ? $_SESSION['subject'] : '';
$message = (!empty($_SESSION['message'])) ? $_SESSION['message'] : '';
$format = (!empty($_SESSION['format'])) ? $_SESSION['format'] : '';
$draft = (!empty($_SESSION['draft'])) ? $_SESSION['draft'] : '';
$preheader = (!empty($_SESSION['preheader'])) ? $_SESSION['preheader'] : '';
$sender_email = (!empty($_SESSION['sender_email'])) ? $_SESSION['sender_email'] : '';
$list_id = (!empty($_POST['list_id'])) ? (($_POST['list_id']) + 0) : '';
$list_id = (!empty($_GET['list_id']) && empty($list_id)) ? (($_GET['list_id']) + 0) : (($list_id) + 0);
$begin = (!empty($_POST['begin'])) ? $_POST['begin'] : '';
$begin = (!empty($_GET['begin']) && empty($begin)) ? (($_GET['begin']) + 0) : 0;
$msg_id = (!empty($_GET['msg_id'])) ? (($_GET['msg_id']) + 0) : '';
$sn = (!empty($_GET['sn'])) ? (($_GET['sn']) + 0) : '';
$error = (!empty($_GET['error'])) ? $_GET['error'] : '';
$encode = (!empty($_GET['encode']) && $_GET['encode'] == 'base64') ? 'base64' : 'quoted-printable';
$force = (!empty($_POST['force'])) ? $_POST['force'] : '';
$force = (!empty($_GET['force']) && empty($force)) ? $_GET['force'] : '';
$tPath = ($row_config_globale['path'] == '' ? '/' : '/'.$row_config_globale['path']);
$tPath = str_replace('//','/',$tPath);
switch ($step) {
case "send":
if (isset($force) && $force == 'true')
touch('logs/__SEND_PROCESS__' . $list_id . '.pid');
if (!file_exists('logs/__SEND_PROCESS__' . $list_id . '.pid')) {
if ($_SESSION['dr_log'] == 'Y' && ($begin < $sn)) {
loggit($_SESSION['dr_id_user'] . '.log', $_SESSION['dr_id_user'] . ' a interrompu un envoi de campagne "' . $subject . '" par "' . $sender_email . '" en ajax');
}
$arr = array(
'TTS' => 'Envoi stoppé'
);
echo json_encode($arr);
die();
}
$tts = 0;
$start = microtime(true);
$dontlog = 0;
if (!$handler = @fopen('logs/list' . $list_id . '-msg' . $msg_id . '.txt', 'a+')) {
$dontlog = 1;
}
$daylog = @fopen('logs/daylog-' . date("Y-m-d") . '.txt', 'a+');
$limit = $row_config_globale['sending_limit'];
$mail = new PHPMailer();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->CharSet = $row_config_globale['charset'];
$mail->ContentType = "text/html";
$mail->Encoding = "quoted-printable";
$mail->PluginDir = "include/lib/";
$msg = get_message($cnx, $row_config_globale['table_archives'], $msg_id);
$newsletter = getConfigSender($cnx, $row_config_globale['table_senders'], $msg['sender_email']);
$sender_email = $newsletter['email'];
$sender_name = $newsletter['name_organisation'];
$reply_email = $newsletter['email_reply'];
if (empty($sender_email)) {
$emptysender = getConfig($cnx, $list_id, $row_config_globale['table_listsconfig']);
$sender_email = $emptysender['from_addr'];
$sender_name = $emptysender['from_name'];
$reply_email = $emptysender['from_addr'];
}
// recherche du mail de bounce (retour des non distribués), du particulier au général, sinon, par défaut : $bounce_mail
if (empty(trim($newsletter['bounce_email']))) { // from array $newsletter : particular desc
if (empty(trim($bounce_mail))) { // from config_bounce.php : global desc
$bounce_email = $emptysender['from_addr']; // from array $emptysender : default desc
} else {
$bounce_email = $bounce_mail;
}
} else {
$bounce_email = $newsletter['bounce_email'];
}
$mail->AddReplyTo($reply_email);
$mail->SetFrom($sender_email, $sender_name);
$mail->Sender = $bounce_email;
$addr = getAddress($cnx, $row_config_globale['table_email'], $list_id, $begin, $limit, $msg_id);
if ($type_env == 'dev') {
$daylogmsg = "LIST_ID : $list_id\tBEGIN : $begin\tLIMIT : $limit\tMSG_ID : $msg_id\n";
fwrite($daylog, $daylogmsg, strlen($daylogmsg));
}
$format = $msg['type'];
$list_pj = $cnx->query("SELECT *
FROM " . $row_config_globale['table_upload'] . "
WHERE list_id=$list_id
AND msg_id=$msg_id
ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
if (count($list_pj) > 0) {
foreach ($list_pj as $item) {
$mail->AddAttachment('upload/' . $item['name']);
}
}
$message = stripslashes($msg['message']);
$to_replace = array(" ","\t","\n","\r","\0","\x0B","\xA0");
$subject = stripslashes($msg['subject']);
$message = str_replace($to_replace, " ", $message);
if (strpos($message, '') === false) {
$message = '' . $message;
}
if (strpos($message, '') === false) {
$message = '[[SUBJECT]]' . $message;
} elseif (strpos($message, '[[SUBJECT]]') === false && strpos($message, '') !== false) {
$message = preg_replace("/(.*)<\/title>/","",$message,1);
$message = '[[SUBJECT]]' . $message;
}
$header = '
';
$message = str_replace('[[SUBJECT]]', $header.'' . $subject . '', $message);
$preHeaderDesc = stripslashes($msg['preheader']);
$preHeader = "";
$message = str_replace('', ' .preHeader {display:none!important;}'.$preHeader, $message);
$messageSource = str_replace(" ", " ", $message);
if ($format == "html") {
$mail->IsHTML(true);
}
$mail->WordWrap = 76;
if (file_exists("include/DKIM/DKIM_config.php") && ($row_config_globale['sending_method'] == 'smtp' || $row_config_globale['sending_method'] == 'php_mail')) {
include("include/DKIM/DKIM_config.php");
$mail->DKIM_domain = $DKIM_domain;
$mail->DKIM_private = $DKIM_private;
$mail->DKIM_selector = $DKIM_selector;
$mail->DKIM_passphrase = $DKIM_passphrase;
$mail->DKIM_identity = $DKIM_identity;
}
$to_send = count($addr);
$view_last_send_mails = "";
$mail->SMTPKeepAlive = true;
for ($i = 0; $i < $to_send; $i++) {
$last_id_send = $addr[$i]['id'];
$cnx->query("UPDATE " . $row_config_globale['table_send_suivi'] . "
SET nb_send=nb_send+1,last_id_send=" . $last_id_send . "
WHERE `msg_id`='" . $msg_id . "' AND `list_id`='" . $list_id . "'");
$time_info = "";
$begintimesend = microtime(true);
$unsubLink = "";
$headtrc = "";
$body = "";
$message = $messageSource;
$mail->ClearAllRecipients();
$mail->ClearCustomHeaders();
$mail->AddAddress($addr[$i]['email']);
$view_last_send_mails .= $addr[$i]['email'];
include("include/lib/switch_smtp.php");
$mail->XMailer = ' ';
$mail->addCustomHeader("List-Unsubscribe",'<'. $row_config_globale['base_url'] . $tPath . 'subscription.php?i=' . $msg_id . '&list_id='
. $list_id . '&op=leave&email_addr=' . $addr[$i]['email'] . '&h=' . $addr[$i]['hash'] . '>'
. ( $sender_email != '' ? ', ' : '' )
);
if ($row_config_globale['active_tracking'] == '1') {
$trac = "
";
} else {
$trac = "";
}
if ($format == "html") {
if ( $row_config_globale['active_tracking'] == '1' ) {
$new_url = 'href="' . $row_config_globale['base_url'] . $tPath . 'r.php?m=' . $msg_id . '&h=' . $addr[$i]['hash'] . '&l=' . $list_id . '&r=';
$message = preg_replace_callback('/href="(http[s]?:\/\/)([^"]+)"/', function($matches) {
global $new_url;
return $new_url . (urlencode(@$matches[1] . $matches[2])) . '"';
}, $message);
}
if (strpos($message, '') !== false) {
$message = str_replace('', '', $message);
$message = str_replace('