<?php
defined('IN_HS') or exit('Access Denied');

if($HS['sendmailtype'] == 'mail')
{
	function sendmail($mail_to, $mail_subject, $mail_body, $mail_from = '')
	{
		global $CONFIG,$HS;
		$mail_from = $mail_from ? $mail_from : $HS['sitename']." <".$HS['smtpuser'].">";
		if($HS['enablesignature']) $mail_body.=$HS['signature'];
		$mail_subject = str_replace("\r", '', str_replace("\n", '', $mail_subject));
		$mail_body = str_replace("\r\n.", " \r\n..", str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $mail_body)))));
		$mail_body = str_replace("\r", '', $mail_body);

		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=".$CONFIG['charset']."\r\n";
		$headers .= "From: $mail_from\r\n";

		return strpos($mail_to, ',') ? @mail($mail_from, $mail_subject, $mail_body, $headers."Bcc: $mail_to") :	@mail($mail_to, $mail_subject, $mail_body, $headers);
	}
}
elseif($HS['smtpuser'])
{
	require_once HS_ROOT.'/include/smtp.class.php';

	$smtp = new smtp($HS['smtphost'], $HS['smtpport'], TRUE, $HS['smtpuser'], $HS['smtppass']);
	$smtp->debug = FALSE;

	function sendmail($mail_to, $mail_subject, $mail_body, $mail_from = '')
	{
		global $smtp,$HS;
		$mail_to = trim($mail_to);
		$mail_from = $mail_from ? $mail_from : $HS['sitename']." &lt;".$HS['smtpuser']."&gt;";
		if($HS['enablesignature']) $mail_body.=$HS['signature'];
		$mail_subject = str_replace("\r", '', str_replace("\n", '', $mail_subject));
		$mail_body = str_replace("\r\n.", " \r\n..", str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $mail_body)))));
		$mail_from = "\"".$HS['sitename']."\" <".$HS['smtpuser'].">";
		return strpos($mail_to, ',') ? $smtp->sendmail($HS['smtpuser'],$mail_from,$mail_subject,$mail_body,'HTML',$mail_to) : $smtp->sendmail($mail_to,$mail_from,$mail_subject,$mail_body,"HTML");	
	}	
}
?>