Viewing file: send.php (5.93 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
include("../include/lib/class.phpmailer.php");
include("../include/config.php");
include("../include/lib/libconfig.php");
include("../include/lib/libnewsletter.php");
include("include/function.php");
include("include/iconv.php");
include("../include/db/db_".$db_type.".inc.php");
$conf = new config();
$conf->getConfig($hostname,$login ,$pass,$database, $table_global_config);
if(empty($conf->language)) $conf->language="english";
include("../include/lang/".$conf->language.".php");
//check authentification
$form_pass = (empty($_POST['form_pass']) ? "" : $_POST['form_pass']);
if(!checkAdminAccess($conf->admin_pass, $form_pass)){
header("Location:index.php");
exit();
}
$step = (empty($_GET['step']) ? "" : $_GET['step']);
$subject = (!empty($_POST['subject'])) ? $_POST['subject'] : '';
$message = (!empty($_POST['message'])) ? $_POST['message'] : '';
$format = (!empty($_POST['format'])) ? $_POST['format'] : '';
$list_id = (!empty($_POST['list_id'])) ? $_POST['list_id'] : '';
$list_id = (!empty($_GET['list_id']) && empty($list_id)) ? $_GET['list_id'] : $list_id;
$begin = (!empty($_POST['begin'])) ? $_POST['begin'] : '';
$begin = (!empty($_GET['begin']) && empty($begin)) ? $_GET['begin'] : 0;
$msg_id = (!empty($_GET['msg_id'])) ? $_GET['msg_id'] : '';
$sn = (!empty($_GET['sn'])) ? $_GET['sn'] : '';
$error = (!empty($_GET['error'])) ? $_GET['error'] : '';
switch($step){
case "send":
// open log file
$dontlog = 0;
if ( !$handler = @fopen('./logs/'.date("Ymd").'-list'.$list_id.'-msg'.$msg_id.'.log', 'a+'))
$dontlog = 1;
$limit = $conf->sending_limit;
$mail = new PHPMailer();
$mail->CharSet= $conf->charset;;
$mail->PluginDir= "../include/lib/";
switch($conf->sending_method){
case "smtp":
$mail->IsSMTP();
$mail->Host = $conf->smtp_host;
if($conf->smtp_auth){
$mail->SMTPAuth = true;
$mail->Username = $conf->smtp_login;
$mail->Password = $conf->smtp_pass;
}
break;
case "php_mail":
$mail->IsMail();
break;
case "online_mail":
$mail->IsOnlineEMail();
break;
default:
break;
}
$newsletter = new Newsletter();
$newsletter->getConfig($hostname,$login ,$pass,$database, $list_id,$conf->table_listsconfig);
$mail->From = $newsletter->from;
$mail->FromName = (strtoupper($conf->charset) == "UTF-8" ? $newsletter->from_name :
iconv( "UTF-8", $conf->charset , $newsletter->from_name));
//get address
$addr = $newsletter->getAddress($conf->table_email,$begin,$limit);
$msg = get_message($hostname,$login ,$pass,$database, $conf->table_archives,$msg_id);
$format = $msg[0];
$subject = stripslashes($msg[1]);
$message = stripslashes($msg[2]);
if($format == "html") $message .="<br />";
$message.= translate("SEND_UNSUBSCRIPTION_LINK");
// $mail->WordWrap = 50;
if($format=="html") $mail->IsHTML(true); // send as HTML
for($i=0; $i<count($addr) ; $i++){
$unsubLink = "";
$mail->to = array();
$mail->AddAddress($addr[$i]);
if($format=="html") $unsubLink = "<br /><a href=\"".$conf->base_url.$conf->path."subscription.php?list_id=$list_id&op=leave&email_addr=".$addr[$i]."\">";
$unsubLink.= $conf->base_url.$conf->path."subscription.php?list_id=$list_id&op=leave&email_addr=".urlencode($addr[$i]);
if($format=="html") $unsubLink.="</a></body></html>";
$body = "";
if($format == "html") $body.= "<html><head></head><body>";
$body.= $message.$unsubLink;
$subj = (strtoupper($conf->charset) == "UTF-8" ? $subject : iconv( "UTF-8", $conf->charset , $subject));
$body = (strtoupper($conf->charset) == "UTF-8" ? $body : iconv( "UTF-8", $conf->charset , $body));
$mail->Subject = $subj;
$mail->Body = $body;
@set_time_limit(150);
if(!$mail->Send()){
$errstr = ($begin+$i+1)."\t".date("H:i:s")." \t".
$addr[$i]."\t".$mail->ErrorInfo."\r\n";
}else {
$errstr = ($begin+$i+1)."\t".date("H:i:s")." \t".
$addr[$i]."\t OK \r\n";
}
if(!$dontlog) fwrite($handler, $errstr, strlen($errstr));
}
$begin+=$limit;
if($begin<$sn){
header("location:send.php?step=send&error=$error&begin=$begin&list_id=$list_id&msg_id=$msg_id&sn=$sn");
} else {
$errstr = "------------------------------------------------------------\r\n";
$errstr.= "Finished at ".date("H:i:s")."\r\n";
$errstr.= "============================================================\r\n";
if(!$dontlog) fwrite($handler, $errstr, strlen($errstr));
if(!$dontlog) fclose($handler);
header("location:index.php?page=compose&op=done&error=$error&list_id=$list_id&errorlog=$dontlog");
}
break;
default:
$conf = new config();
$conf->getConfig($hostname,$login ,$pass,$database, $table_global_config);
$message =urldecode($message);
// save the message in the database
$date=date("Y-m-d H:i:s");
$msg_id = save_message($hostname,$login ,$pass,$database, $conf->table_archives, addslashes($subject), $format, addslashes($message), $date, $list_id);
// open log file
$dontlog = 0;
if ( !$handler = @fopen('./logs/'.date("Ymd").'-list'.$list_id.'-msg'.$msg_id.'.log', 'a+'))
$dontlog = 1;
$newsletter = new Newsletter();
$newsletter->getConfig($hostname,$login ,$pass,$database, $list_id,$conf->table_listsconfig);
$num = $newsletter->getSubscribersNumbers($conf->table_email);
$errstr = "============================================================\r\n";
$errstr.= date("d M Y")."\r\n";
$errstr.= "Started at ".date("H:i:s")."\r\n";
$errstr.= "N° \t Date \t\t Recipient \t\t Status \r\n";
$errstr.= "------------------------------------------------------------\r\n";
if(!$dontlog) fwrite($handler, $errstr, strlen($errstr));
if(!$dontlog) fclose($handler);
header("location:send.php?step=send&begin=0&list_id=$list_id&msg_id=$msg_id&sn=$num&error=0");
break;
}
?>
|