<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara
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.
*/
$send_to=get('to');
$send_cc=get('cc');
$send_bcc=get('bcc');
$send_subject=get('subject');
$send_body=get('body');
$memo=get('memo');
require_once(cfg_data_path.'/script/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->PluginDir=cfg_data_path.'/script/phpmailer/';
$mail->SetLanguage('en',cfg_data_path.'/script/phpmailer/language/');
$mail->IsSMTP(); // send via SMTP
$mail->Host = cfg_smtp_server; // SMTP servers
if(strlen(cfg_smtp_passwd)>0)
{
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = cfg_smtp_user; // SMTP username
$mail->Password = cfg_smtp_passwd; // SMTP password
}
$mail->From = cfg_smtp_from;
$send_array=explode(',',$send_to);
for($tmp_ii=0;$tmp_ii<count($send_array);$tmp_ii++)
if(trim($send_array[$tmp_ii]))
$mail->AddAddress(trim($send_array[$tmp_ii]));
if($send_cc)
{
$send_array=explode(',',$send_cc);
for($tmp_ii=0;$tmp_ii<count($send_array);$tmp_ii++)
if(trim($send_array[$tmp_ii]))
$mail->AddCC(trim($send_array[$tmp_ii]));
}
if($send_bcc)
{
$send_array=explode(',',$send_bcc);
for($tmp_ii=0;$tmp_ii<count($send_array);$tmp_ii++)
if(trim($send_array[$tmp_ii]))
$mail->AddBCC(trim($send_array[$tmp_ii]));
}
$mail->AddReplyTo(cfg_smtp_from,cfg_skin_name);
$mail->WordWrap = 50; // set word wrap
$attach1=get('attach1');
if($attach1)
$mail->AddAttachment(cfg_data_path.'/upload/'.$attach1); // attachment
$attach2=get('attach2');
if($attach2)
$mail->AddAttachment(cfg_data_path.'/upload/'.$attach2); // attachment
$attach3=get('attach3');
if($attach3)
$mail->AddAttachment(cfg_data_path.'/upload/'.$attach3); // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
$mail->Subject = $send_subject;
$mail->Body = nl2br($send_body);
if(!$mail->Send())
{
//echo "Message was not sent <p>";
$email_file=rand(10000000,99999999);
addpath(cfg_data_path.'/config/not_sent');
$fp=fopen(cfg_data_path.'/config/not_sent/'.$email_file.'.txt','wb');
fwrite($fp,$send_to.CRLF.'-------------------'.CRLF.''.$send_subject.CRLF.'-------------------'.CRLF.$send_body);
fclose($fp);
mylog('MAILER ERROR ('.$email_file.') '.$mail->ErrorInfo);
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
$group='email';
$variable_array['sysId']='0';
$variable_array['sysGroupBy']=$group;
$variable_array['sysValidFrom']=date('Ymd');
$variable_array['sysValidTo']=99991231;
$variable_array['sysValid']=1;
$variable_array['sysComment']='Email sent';
$variable_array['Send From']=USERNAME;
$variable_array['Send Date']=date('Ymd');
$variable_array['Send To']=$send_to;
$variable_array['Send CC']=$send_cc;
$variable_array['Send BCC']=$send_bcc;
$variable_array['Send Subject']=$send_subject;
$variable_array['Send Body']=$send_body;
$variable_array['Memo']=$memo;
$variable_array['Send Attach 1']=$attach1;
$variable_array['Send Attach 2']=$attach2;
$variable_array['Send Attach 3']=$attach3;
//USEREXIT OnSave
$userexit='onsave';
if(file_exists(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt'))
{
include(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt');
}
else
{
include(cfg_data_path.'/script/userexit/exit_'.$userexit.'.txt');
}
if($variable_array['MyBag']=='')
$variable_array['MyBag']=$bag;
$variable_array['MyBag']=purename($variable_array['MyBag']);
$id=save($variable_array);
//$search=$group.' sysId='.$id;
if(!$script)
$search='sysId='.$id;
}
?>