<?php
/* -----------------------------------------------------------------------------------------
   $Id: xtc_php_mail.inc.php,v 1.2 2008/10/27 09:14:12 cvs Exp $   

   XT-Commerce - community made shopping
   http://www.xt-commerce.com

   Copyright (c) 2003 XT-Commerce
   -----------------------------------------------------------------------------------------
   based on: 
   (c) 2003	 nextcommerce (xtc_php_mail.inc.php,v 1.17 2003/08/24); www.nextcommerce.org


   Released under the GNU General Public License 
   ---------------------------------------------------------------------------------------*/
 
/**
 * send emails
 *
 * @param string $from_email_address
 * @param string $from_email_name
 * @param string $to_email_address
 * @param string $to_name
 * @param string $forwarding_to
 * @param string $reply_address
 * @param string $reply_address_name
 * @param string $path_to_attachement
 * @param string $path_to_more_attachements
 * @param string $email_subject
 * @param string $message_body_html
 * @param string $message_body_plain
 */
function xtc_php_mail($from_email_address, $from_email_name, $to_email_address, $to_name, $forwarding_to, $reply_address, $reply_address_name, $path_to_attachement, $path_to_more_attachements, $email_subject, $message_body_html, $message_body_plain) {
     global $mail_error;

$mail = new PHPMailer();
$mail->PluginDir=DIR_FS_DOCUMENT_ROOT.'includes/classes/';
$mail->CharSet=$_SESSION['language_charset']; 

// IMMER DE!
$mail->SetLanguage("de",DIR_FS_CATALOG.'includes/classes/');
if ($_SESSION['language']=='german') {
$mail->SetLanguage("de",DIR_WS_CLASSES);
} else {
	$mail->SetLanguage("de",DIR_WS_CLASSES);
}

if (EMAIL_TRANSPORT=='smtp') {
$mail->IsSMTP(); 
$mail->SMTPKeepAlive = true;                                    // set mailer to use SMTP
$mail->SMTPAuth = SMTP_AUTH;                                    // turn on SMTP authentication true/false
$mail->Username = SMTP_USERNAME;                                // SMTP username
$mail->Password = SMTP_PASSWORD;                                // SMTP password
$mail->Host = SMTP_MAIN_SERVER . ';' . SMTP_Backup_Server;      // specify main and backup server "smtp1.example.com;smtp2.example.com"
}
        
if (EMAIL_TRANSPORT=='sendmail') {                              // set mailer to use SMTP
$mail ->IsSendmail();        
$mail->Sendmail=SENDMAIL_PATH;
}
if (EMAIL_TRANSPORT=='mail') {
$mail ->IsMail();                                                                                 
}  
define('EMAIL_USE_HTML','true');
if ( EMAIL_USE_HTML=='true' )                                   // set email format to HTML
{
     $mail -> IsHTML(true);
     $mail->Body    = $message_body_html;
     // remove html tags
     $message_body_plain=str_replace('<br>'," \n",$message_body_plain);
     $message_body_plain=strip_tags($message_body_plain);
     $mail->AltBody = $message_body_plain;
}
else
{
     $mail -> IsHTML(false);
     //remove html tags
     $message_body_plain=str_replace('<br>'," \n",$message_body_plain);
     $message_body_plain=strip_tags($message_body_plain);
     $mail->Body    = $message_body_plain;
} 

$mail->From = $from_email_address;
$mail->Sender = $from_email_address;
$mail->FromName = $from_email_name;
$mail->AddAddress($to_email_address, $to_name);
if ($forwarding_to!='') $mail->AddBCC($forwarding_to);
$mail->AddReplyTo($reply_address, $reply_address_name);

$mail->WordWrap = 50;                                             // set word wrap to 50 characters

if($path_to_attachement != ''){
	$mail->AddAttachment($path_to_attachement);                     // add attachments
}
if($path_to_more_attachements != ''){
	$mail->AddAttachment($path_to_more_attachements);               // optional name                                          
}
$mail->Subject = $email_subject;


	if(!$mail->Send())
	{
	   echo "Message was not sent <p>";
	   echo "Mailer Error: " . $mail->ErrorInfo;
	   return false;
	   exit;
	}
	return true;
}
   
?>