require_once("../../config.php");
require_once("../../modules/EcmDocs/uploadfile.php");
//require_once("dirstree.php");
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set names utf8");
mysql_query("set charaecterset utf8");
if($_POST['send'])
{
/*
function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments=false)
{
$eol="\r\n";
$mime_boundary=md5(time());
# Common Headers
$headers .= 'From: Celtic CRM<'.$fromaddress.'>'.$eol;
$headers .= 'Reply-To: Celtic CRM<'.$fromaddress.'>'.$eol;
$headers .= 'Return-Path: Celtic CRM<'.$fromaddress.'>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]["file"]))
{
# File for Attachment
$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
$handle=fopen($attachments[$i]["file"], 'rb');
$f_contents=fread($handle, filesize($attachments[$i]["file"]));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
fclose($handle);
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$attachments[$i]["name"]."\"".$eol;
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$attachments[$i]["name"]."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
}
}
}
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;
# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-2".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= strip_tags(str_replace("
", "\n", $body)).$eol.$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-2".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
}
*/
if($_POST['id_file'])
{
$row=mysql_fetch_array(mysql_query("select name,filename from ecmfiles_versions where id='".$_POST['id_file']."'"));
$attachments = array("file" => "../../".$row['filename'], "content_type" =>"application/pdf", "name"=>$row['name']);
}
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->PluginDir = "phpmailer/";
$mail->From = "crm@celtic.pl"; //adres naszego konta
$mail->FromName = "CRM";//nagłówek From
//$mail->Host = "NASZ.SERWER.SMTP";//adres serwera SMTP
//$mail->Mailer = "smtp";
//$mail->Username = "tester@KONTO";//nazwa użytkownika
//$mail->Password = "HASLO";//nasze hasło do konta SMTP
//$mail->SMTPAuth = true;
//$mail->SetLanguage("en", "phpmailer/language/");
$mail->Subject = $_POST['subject'];//temat maila
// w zmienną $text_body wpisujemy treść maila
$text_body = $_POST['body'];
$mail->Body = $text_body;
$mail->AddAttachment($attachments['file'],$attachments['name'],"8bit","application/pdf");
// adresatów dodajemy poprzez metode 'AddAddress'
foreach($_POST['user'] as $emails)$mail->AddAddress($emails,$emails);
if(!$mail->Send())
echo "There has been a mail error
";
echo $mail->ErrorInfo."
";
// Clear all addresses and attachments
$mail->ClearAddresses();
$mail->ClearAttachments();
# Use relative paths to the attachments
/*
if($_POST['filename']['name'])
{
$handle=upload_file('filename','cache/upload');
$attachments = array(array("file" => $handle, "content_type" => "application/pdf", "name"=>$_FILES['filename']['name']));
}*/
# Message Body
$body=;
ob_start();
send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments);
}
?>