<?php
// --------------------------------------------------------------------------
//
// Esvon Classifieds v.4.0
// Copyright(C), Esvon LTD, 2001-2010, All Rights Reserved.
// E-mail: hide@address.com
//
// All forms of reproduction, including, but not limited to, internet posting,
// printing, e-mailing, faxing and recording are strictly prohibited.
// One license required per site running Esvon Classifieds.
// To obtain a license for using Esvon Classifieds, please register at
// http://www.esvon.com/pg/products/p_classifieds/
//
// --------------------------------------------------------------------------
if(!defined('SITE_PATH')) die('Access Denied');
require_once SITE_PATH.'inc/class.phpmailer.php';
if(!function_exists('html_entity_decode')) hwLoadFunction('html_entity_decode');
class Hw_Mail extends PHPMailer {
var $_uid = 0;
function Hw_Mail(){
$this->CharSet = $GLOBALS['CHARSET'];
if(MAILER == 'smtp'){ // DIRECTORY_SEPARATOR == '\\' [win]
$this->Mailer = 'smtp';
$this->PluginDir = SITE_PATH.'inc/';
$this->Host = SMTP_HOST ? SMTP_HOST : ini_get("SMTP");
$this->Port = SMTP_PORT ? SMTP_PORT : ini_get("smtp_port");
//$this->SMTPDebug = 1;
if(EN_SMTP_AUTH){
$this->Username = SMTP_USER;
$this->Password = SMTP_PW;
}
}
}
function setUserID($id){
if(ctype_digit((string)$id)) $this->_uid = $id;
}
function sendParsed($to, $from, $subj, $msg, $attach = false){
$tpl_v = $this->_getVarsArray();
// $subj = str_replace("\n",'',$subj);
$subj = EvalBuffer($subj, $tpl_v);
$msg = EvalBuffer($msg, $tpl_v);
$hw_uid = $this->_uid;
if(!$hw_uid) $hw_uid = (int)hwSessionGetVar('userid');
if($hw_uid){
static $O_UFS;
static $a_User = array();
if(!isset($O_UFS)) $O_UFS = &Factory::singleton('FieldsSet', '{user_fields}');
if(!array_key_exists($hw_uid, $a_User)){
global $db;
$a_User[$hw_uid] = $db->one_assoc('SELECT * FROM '.TBL_USER." WHERE id='$hw_uid'");
}
$msg = EvalBuffer($msg, $O_UFS->FillCustomFieldsArray($a_User[$hw_uid]));
if(count($a_User)>50) $a_User = array();
}
hwProcessTags($msg);
if(preg_match('/<!-- SUBJECT:(.*?)-->.*?[\r\n]+/',$msg,$m)){
$subj = trim($m[1]);
$msg = str_replace($m[0],'',$msg);
}
if(preg_match('/<html/i',$msg)) {
$this->IsHTML(TRUE);
if($msg[0] != '<'){
list($msg_alt, $msg) = preg_split('/<html/i', $msg, 2);
$msg_alt = trim($msg_alt);
if($msg_alt) $this->AltBody = $this->_html2text($msg_alt);
$msg = '<html'.$msg;
}
}
else $msg = $this->_html2text($msg);
// $this->WordWrap = 50;
$from = trim($from);
if(strpos($from,'<')!==false){
$z = preg_split('/(\s+<|>\s+)/', $from);
if($from[0]=='<'){ $from = substr($z[0],1); $from_name = $z[1]; }
else{ $from = substr($z[1],0,-1); $from_name = $z[0]; }
$from_name = trim(str_replace('"','',$from_name));
}
else $from_name = COMPANY;
$this->From = $from;
$this->FromName = $from_name;
$this->AddAddress($to);
$this->AddReplyTo($from);
$this->Subject = $subj;
$this->Body = $msg;
if($attach){
if(!is_array($attach)) $attach = array($attach);
foreach($attach as $k=>$f) $this->AddAttachment($f, is_numeric($k) ? '' : $k);
}
//FileWrite('c:/mails.txt', $msg."\n\n", true);
//return;
$this->Send();
}
function _html2text($s){
$s = preg_replace('/(?:\s*<(?:br|p)(?: \/)?>\s*){1,}/i', "\n", $s);
$s = strip_tags($s);
return html_entity_decode($s, ENT_QUOTES);
}
function _getVarsArray(){
static $host;
if(!isset($host)){
$v = parse_url(SITE_URL);
$host = $v['host'];
}
return array(
'ADMIN_EMAIL' => ADMIN_EMAIL,
'SITE_URL' => SITE_URL,
'SITE_HOST' => $host,
'COMPANY' => COMPANY,
'CURR_SIGN' => CURR_SIGN,
'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'],
'HTTP_X_FORWARDED_FOR' => html_esc($_SERVER['HTTP_X_FORWARDED_FOR']),
'ADMIN_DIR' => ADMIN_DIR,
);
}
}