Location: PHPKode > projects > PhpRechnung > phpRechnung/addressbook/emailf.php
<?php
/*	emailf.php

	phpInvoice - is easy-to-use Web-based multilingual accounting software.
	Copyright (C) 2001 - 2008 Edy Corak < phprechnung at ecorak dot net >

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

require_once("../include/phprechnung.inc.php");
require_once("../include/smarty.inc.php");
if ($PHPSendMail == "1" ) {
	require_once("../include/mail.inc.php");
}

CheckUser();
CheckSession();

if(isset($_POST['myID'])) {
	$myID = $_POST['myID'];
}
if(isset($_POST['page'])) {
	$page = $_POST['page'];
}
if(isset($_POST['infoID'])) {
	$infoID = $_POST['infoID'];
}
if(isset($_POST['CompanyName'])) {
	$CompanyName = $_POST['CompanyName'];
}
if(isset($_POST['EmailFrom'])) {
	$EmailFrom = $_POST['EmailFrom'];
}
if(isset($_POST['EmailTo'])) {
	$EmailTo = $_POST['EmailTo'];
}
if(isset($_POST['EmailCc'])) {
	$EmailCc = $_POST['EmailCc'];
}
if(isset($_POST['EmailBcc'])) {
	$EmailBcc = $_POST['EmailBcc'];
}
if(isset($_POST['EmailSubject'])) {
	$EmailSubject = $_POST['EmailSubject'];
}
if(isset($_POST['EmailPriority'])) {
	$EmailPriority = $_POST['EmailPriority'];
}
if(isset($_POST['EmailText'])) {
	$EmailText = $_POST['EmailText'];
}

if(isset($_POST['Customer'])) {
	$Customer = $_POST['Customer'];
}

if(isset($_POST['PrintName1'])) {
	$PrintName1 = $_POST['PrintName1'];
}
if(isset($_POST['Date_From1'])) {
	$Date_From1 = $_POST['Date_From1'];
}
if(isset($_POST['Date_Till1'])) {
	$Date_Till1 = $_POST['Date_Till1'];
}
if(isset($_POST['CustomerID'])) {
	$CustomerID = $_POST['CustomerID'];
}
if(isset($_POST['Prefix1'])) {
	$Prefix1 = $_POST['Prefix1'];
}
if(isset($_POST['Firstname1'])) {
	$Firstname1 = $_POST['Firstname1'];
}
if(isset($_POST['Lastname1'])) {
	$Lastname1 = $_POST['Lastname1'];
}
if(isset($_POST['Title11'])) {
	$Title11 = $_POST['Title11'];
}
if(isset($_POST['Company1'])) {
	$Company1 = $_POST['Company1'];
}
if(isset($_POST['Department1'])) {
	$Department1 = $_POST['Department1'];
}
if(isset($_POST['Address1'])) {
	$Address1 = $_POST['Address1'];
}
if(isset($_POST['Country1'])) {
	$Country1 = $_POST['Country1'];
}
if(isset($_POST['Postalcode1'])) {
	$Postalcode1 = $_POST['Postalcode1'];
}
if(isset($_POST['City1'])) {
	$City1 = $_POST['City1'];
}
if(isset($_POST['Stateprov1'])) {
	$Stateprov1 = $_POST['Stateprov1'];
}
if(isset($_POST['Position11'])) {
	$Position11 = $_POST['Position11'];
}
if(isset($_POST['Initials1'])) {
	$Initials1 = $_POST['Initials1'];
}
if(isset($_POST['Salutation1'])) {
	$Salutation1 = $_POST['Salutation1'];
}
if(isset($_POST['Phonehome1'])) {
	$Phonehome1 = $_POST['Phonehome1'];
}
if(isset($_POST['Phoneoffi1'])) {
	$Phoneoffi1 = $_POST['Phoneoffi1'];
}
if(isset($_POST['Phoneothe1'])) {
	$Phoneothe1 = $_POST['Phoneothe1'];
}
if(isset($_POST['Phonework1'])) {
	$Phonework1 = $_POST['Phonework1'];
}
if(isset($_POST['Mobile1'])) {
	$Mobile1 = $_POST['Mobile1'];
}
if(isset($_POST['Pager1'])) {
	$Pager1 = $_POST['Pager1'];
}
if(isset($_POST['Fax1'])) {
	$Fax1 = $_POST['Fax1'];
}
if(isset($_POST['Email1'])) {
	$Email1 = $_POST['Email1'];
}
if(isset($_POST['Url1'])) {
	$Url1 = $_POST['Url1'];
}
if(isset($_POST['Note1'])) {
	$Note1 = $_POST['Note1'];
}
if(isset($_POST['AltField11'])) {
	$AltField11 = $_POST['AltField11'];
}
if(isset($_POST['AltField21'])) {
	$AltField21 = $_POST['AltField21'];
}
if(isset($_POST['AltField31'])) {
	$AltField31 = $_POST['AltField31'];
}
if(isset($_POST['AltField41'])) {
	$AltField41 = $_POST['AltField41'];
}
if(isset($_POST['Category1'])) {
	$Category1 = $_POST['Category1'];
}
if(isset($_POST['MethodOfPayment1'])) {
	$MethodOfPayment1 = $_POST['MethodOfPayment1'];
}
if(isset($_POST['Birthday1'])) {
	$Birthday1 = $_POST['Birthday1'];
}
if(isset($_POST['Order'])) {
	$Order = $_POST['Order'];
}
if(isset($_POST['Sort'])) {
	$Sort = $_POST['Sort'];
}

$Searchstring = "CustomerID=$CustomerID&Prefix1=$Prefix1&Title11=$Title11&Firstname1=$Firstname1&Initials1=$Initials1&Lastname1=$Lastname1&Phonehome1=$Phonehome1&Salutation1=$Salutation1&Mobile1=$Mobile1&Address1=$Address1&Fax1=$Fax1&Stateprov1=$Stateprov1&Email1=$Email1&Postalcode1=$Postalcode1&City1=$City1&Url1=$Url1&Company1=$Company1&Phonework1=$Phonework1&Department1=$Department1&Phoneoffi1=$Phoneoffi1&Position11=$Position11&Phoneothe1=$Phoneothe1&Pager1=$Pager1&Note1=$Note1&Altfield11=$AltField11&Altfield21=$AltField21&Altfield31=$AltField31&Altfield41=$AltField41&Country1=$Country1&Date_From1=$Date_From1&Date_Till1=$Date_Till1&Birthday1=$Birthday1&Category1=$Category1";

function UserInput($mark) {
	global $smarty, $myID, $page, $infoID, $EmailTo, $EmailCc, $EmailBcc, $EmailSubject,
	$EmailPriority, $EmailText, $Date_From1, $Date_Till1, $CustomerID, $Prefix1,
	$Title11, $Firstname1, $Initials1, $Lastname1, $Phonehome1, $Salutation1, $Mobile1, $Address1,
	$Fax1, $Stateprov1, $Email1, $Postalcode1, $City1, $Url1, $Company1, $Phonework1, $Department1,
	$Phoneoffi1, $Position11, $Phoneothe1, $Pager1, $Note1, $AltField11, $AltField21, $AltField31,
	$AltField41, $Country1, $Birthday1, $Category1, $MethodOfPayment1, $PrintName1, $Customer, $Order, $Sort;
	$smarty->assign("myID",$myID);
	$smarty->assign("page",$page);
	$smarty->assign("infoID","$infoID");
	$smarty->assign("EmailTo","$EmailTo");
	$smarty->assign("EmailCc","$EmailCc");
	$smarty->assign("EmailBcc","$EmailBcc");
	$smarty->assign("EmailSubject","$EmailSubject");
	$smarty->assign("EmailPriority","$EmailPriority");
	$smarty->assign("EmailText","$EmailText");
	$smarty->assign("Customer","$Customer");
	$smarty->assign("Date_From1","$Date_From1");
	$smarty->assign("Date_Till1","$Date_Till1");
	$smarty->assign("CustomerID","$CustomerID");
	$smarty->assign("Prefix1","$Prefix1");
	$smarty->assign("Firstname1","$Firstname1");
	$smarty->assign("Lastname1","$Lastname1");
	$smarty->assign("Title11","$Title11");
	$smarty->assign("Company1","$Company1");
	$smarty->assign("Department1","$Department1");
	$smarty->assign("Address1","$Address1");
	$smarty->assign("Country1","$Country1");
	$smarty->assign("Postalcode1","$Postalcode1");
	$smarty->assign("City1","$City1");
	$smarty->assign("Stateprov1","$Stateprov1");
	$smarty->assign("Position11","$Position11");
	$smarty->assign("Initials1","$Initials1");
	$smarty->assign("Salutation1","$Salutation1");
	$smarty->assign("Phonehome1","$Phonehome1");
	$smarty->assign("Phoneoffi1","$Phoneoffi1");
	$smarty->assign("Phoneothe1","$Phoneothe1");
	$smarty->assign("Phonework1","$Phonework1");
	$smarty->assign("Mobile1","$Mobile1");
	$smarty->assign("Pager1","$Pager1");
	$smarty->assign("Fax1","$Fax1");
	$smarty->assign("Email1","$Email1");
	$smarty->assign("Url1","$Url1");
	$smarty->assign("Note1","$Note1");
	$smarty->assign("AltField11","$AltField11");
	$smarty->assign("AltField21","$AltField21");
	$smarty->assign("AltField31","$AltField31");
	$smarty->assign("AltField41","$AltField41");
	$smarty->assign("Category1","$Category1");
	$smarty->assign("MathodOfPayment1","$MethodOfPayment1");
	$smarty->assign("PrintName1","$PrintName1");
	$smarty->assign("Birthday1","$Birthday1");
	$smarty->assign("Order",$Order);
	$smarty->assign("Sort",$Sort);
	$smarty->assign("Mark",$mark);
}

if (!ereg("^([a-zA-Z0-9\.\_\-]+)@([a-zA-Z0-9\.\-]+\.[A-Za-z][A-Za-z]+)$",$EmailTo)) {
	$smarty->assign("FieldError","$a[email_to] - $a[field_error]");
	UserInput("EmailTo");
	$smarty->display('addressbook/emailf.tpl');
} else if (empty($EmailSubject)) {
	$smarty->assign("FieldError","$a[email_subject] - $a[field_error]");
	UserInput("EmailSubject");
	$smarty->display('addressbook/emailf.tpl');
} else if (empty($EmailText)) {
	$smarty->assign("FieldError","$a[email_text] - $a[field_error]");
	UserInput("EmailText");
	$smarty->display('addressbook/emailf.tpl');
} else {
	if(!empty($EmailCc)) {
		$Receiver = "$EmailTo,$EmailCc";
	} else if (!empty($EmailBcc)) {
		$Receiver = "$EmailTo,$EmailBcc";
	} else if (!empty($EmailCc) && (!empty($EmailBcc))) {
		$Receiver = "$EmailTo,$EmailCc,$EmailBcc";
	} else {
		$Receiver = "$EmailTo";	
	}

	if ($PHPSendMail == "1" ) {
		$header["From"] = "$CompanyName <$EmailFrom>";
		$header["To"] = "$EmailTo";
		if(!empty($EmailCc)) $header["Cc"] = "$EmailCc";
		$header["Subject"] = "$EmailSubject";
		$header["Organization"]	= "$CompanyName";
		$header["MIME-Version"]	= "1.0";
		$header["Content-Type"]	= "text/plain; charset=$_SESSION[Charset]";
		$header["X-Priority"] = "$EmailPriority";
		$header["Content-Transfer-Encoding"] = "7bit";
		$header["X-Mailer"] = "$a[programname] - PHP $phpversion";
	} else {
		$header = "From: ".$CompanyName."<".$EmailFrom.">\n";
		if(!empty($EmailCc)) $header .= "Cc: ".$EmailCc."\n";
		if(!empty($EmailBcc)) $header .= "Bcc: ".$EmailBcc."\n";
		$header .= "Organization: ".$CompanyName."\n";
		$header .= "MIME-Version: 1.0\n";
		$header .= "Content-Type: text/plain; charset=$_SESSION[Charset]\n";
		$header .= "X-Priority: ".$EmailPriority."\n";
		$header .= "Content-Transfer-Encoding: 7bit\n";
		$header .= "X-Mailer: ".$a['programname']." - PHP ".PHP_VERSION."\n";
	}

	$body = "$EmailText\n";

	if(!empty($EmailTo)) {
		if($PHPSendMail == "1") {
			$mail_object->send($Receiver, $header, $body);
			$_SESSION['emailID'] = '1';
		} else {
			// If you have safe_mode = On, please delete ,"-f$EmailFrom"
			// because the fifth parameter is not allowed in safe_mode
			//
			mail("$EmailTo",$EmailSubject,$EmailText,$header,"-f$EmailFrom");
			$_SESSION['emailID'] = '1';
		}
		// Database connection
		//
		DBConnect();

		$query2 = "INSERT INTO {$TBLName}syslog (SYSLOGID, CREATED, DESCRIPTION, CREATEDBY, USERGROUP1, USERGROUP2)";
		$query2 .= "VALUES(NULL, '$CurrentDateTime', 'E-Mail - Subject: $EmailSubject - was send by user $_SESSION[Username] (uid=$_SESSION[UserID]) from $IPAddress to E-Mail: $Receiver', 'admin', '1', '2')";
		if ($db->Execute($query2) === false)
		{
			die($db->ErrorMsg());
		}
	}
	else
	{
		$_SESSION['emailID'] = '2';
	}

	if($infoID == '9') {
		Header("Location: $web/addressbook/searchlist.php?myID=$myID&page=$page&Customer=$Customer&Order=$Order&Sort=$Sort&$sessname=$sessid#$myID");
	} else if($infoID == '10') {
		Header("Location: $web/addressbook/searchlist_e.php?myID=$myID&page=$page&$Searchstring&Order=$Order&Sort=$Sort&$sessname=$sessid#$myID");
	} else {
		Header("Location: $web/addressbook/list.php?myID=$myID&page=$page&Order=$Order&Sort=$Sort&$sessname=$sessid#$myID");
	}
}
?>
Return current item: PhpRechnung