This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/core/email.inc.php

218 lines
6.1 KiB
PHP
Raw Normal View History

<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
*
* Originally authored by Tony Landis, AgileBill LLC
*
* Recent modifications by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
2009-08-03 04:10:16 +00:00
* @subpackage Core
*/
2009-08-03 04:10:16 +00:00
/**
* The main AgileBill CORE Mail Class
*
* This class handles the interface to SMTP and Mail() functions.
*
* <code>
* $arr = array(
* 'from_html' => 'true/false' (so we know whether to stripslashes or not)
* 'html' => '0/1',
* 'from_name' => '',
* 'from_email' => '',
* 'priority' => '0/1',
* 'to_email' => 'email@email.com',
* 'to_name' => '',
* 'bcc_list' => array('email@email.com'),
* 'cc_list' => array('email@email.com'),
* 'subject' => '',
* 'body_text' => '',
* 'body_html' => '',
* 'attachments' => array(array('file' => 'file.exe',
* 'data' => 'file data here...'))
* 'server' => 'mail.domain.com',
* 'account' => '',
* 'password' => '');
* </code>
*
* @package AgileBill
* @subpackage Core
*/
2009-08-03 04:10:16 +00:00
class CORE_email {
var $debug=false;
2009-08-03 04:10:16 +00:00
public function PHP_Mail($arr) {
# SET THE SMTP SETTINGS
#ini_set('sendmail_from',@$arr['from_email']);
#ini_set('SMTP',@$arr['server']);
# CC LIST
$cc = '';
if (isset($arr['cc_list']) && is_array($arr['cc_list']))
$cc = implode(',',$arr['cc_list']);
# BCC LIST
$bcc = '';
if (isset($arr['bcc_list']) && is_array($arr['bcc_list']))
$bcc = implode(',',$arr['bcc_list']);
$headers = '';
# FROM:
$headers .= sprintf('From: "%s" <%s>',$arr['from_name'],$arr['from_email'])."\r\n";
$headers .= sprintf('Reply-To: "%s" <%s>',$arr['from_name'],$arr['from_email'])."\r\n";
# HTML/non-HTML version of body & headers
$headers .= "MIME-Version: 1.0\r\n";
if (isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
# Specify MIME version 1.0
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$body = $arr['body_html'];
} else {
# Specify MIME version 1.0
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$body = $arr['body_text'];
}
2009-08-03 04:10:16 +00:00
# CC:
if (trim($cc))
$headers .= sprintf('Cc: %s',$cc)."\r\n";
2009-08-03 04:10:16 +00:00
# BCC:
if (trim($bcc))
$headers .= sprintf('Bcc: %s',$bcc)."\r\n";
### PRIORITY
if(isset($arr['priority']) && $arr['priority'] == '1')
2009-08-03 04:10:16 +00:00
$headers .= "X-Priority: 1\r\n";
else
2009-08-03 04:10:16 +00:00
$headers .= "X-Priority: 3\r\n";
2009-08-03 04:10:16 +00:00
# Strip Slashes
if (! isset($arr['from_html']) || @$arr['html_form'] == false) {
# From database, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
2009-08-03 04:10:16 +00:00
$body = stripslashes($body);
} elseif (@$arr['from_html'] == true && get_magic_quotes_gpc()) {
2009-08-03 04:10:16 +00:00
# Straight from html, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
2009-08-03 04:10:16 +00:00
$body = stripslashes($body);
}
2009-08-03 04:10:16 +00:00
if ($this->debug) {
if (mail($arr['to_email'],$arr['subject'],$body,$headers)) {
global $C_debug;
2009-08-03 04:10:16 +00:00
$C_debug->alert(__FILE__,__METHOD__,sprintf('PHP mail() failed to send message "%s" to "%s"',$arr['subject'],$arr['to_email']));
return false;
}
2009-08-03 04:10:16 +00:00
} else {
if (@mail($arr['to_email'],$arr['subject'],$body,$headers)) {
global $C_debug;
2009-08-03 04:10:16 +00:00
$C_debug->alert(__FILE__,__METHOD__,sprintf('PHP mail() failed to send message "%s" to "%s"',$arr['subject'],$arr['to_email']));
return false;
}
}
2009-08-03 04:10:16 +00:00
return true;
}
2009-08-03 04:10:16 +00:00
public function SMTP_Mail($arr) {
# Include the phpmailer class
require_once(PATH_INCLUDES.'phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
2009-08-03 04:10:16 +00:00
$mail->IsSMTP();
2009-08-03 04:10:16 +00:00
$mail->SMTPAuth = true;
$mail->Host = @$arr['server'];
$mail->Username = @$arr['account'];
$mail->Password = @$arr['password'];
$mail->From = $arr['from_email'];
$mail->FromName = $arr['from_name'];
$mail->AddAddress($arr['to_email'],@$arr['to_name']);
#$mail->AddReplyTo($arr['from_name'], $arr['from_email']);
2009-08-03 04:10:16 +00:00
# CC LIST
if (isset($arr['cc_list']) && is_array($arr['cc_list']))
foreach ($arr['cc_list'] as $email)
$mail->AddCC($email,'');
2009-08-03 04:10:16 +00:00
# BCC LIST
if (isset($arr['bcc_list']) && is_array($arr['bcc_list']))
foreach ($arr['bcc_list'] as $email)
$mail->AddBCC($email,'');
2009-08-03 04:10:16 +00:00
# Strip Slashes
if (! isset($arr['from_html']) || @$arr['html_form'] == false) {
# From database, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
@$arr['body_html'] = stripslashes($arr['body_html']);
@$arr['body_text'] = stripslashes($arr['body_text']);
2009-08-03 04:10:16 +00:00
} elseif (@$arr['from_html'] == true && get_magic_quotes_gpc()) {
2009-08-03 04:10:16 +00:00
# Straight from html, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
@$arr['body_html'] = stripslashes($arr['body_html']);
@$arr['body_text'] = stripslashes($arr['body_text']);
}
2009-08-03 04:10:16 +00:00
# HTML/non-HTML version of body & headers
if (isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
$mail->IsHTML(true);
2009-08-03 04:10:16 +00:00
$mail->Body = @$arr['body_html'];
$mail->AltBody = @$arr['body_text'];
} else {
$mail->IsHTML(false);
2009-08-03 04:10:16 +00:00
$mail->Body = @$arr['body_text'];
$mail->WordWrap = 50;
}
2009-08-03 04:10:16 +00:00
# Subject
$mail->Subject = $arr['subject'];
# PRIORITY
if(isset($arr['priority']) && $arr['priority'] == '1')
2009-08-03 04:10:16 +00:00
$mail->Priority = 1;
else
2009-08-03 04:10:16 +00:00
$mail->Priority = 3;
2009-08-03 04:10:16 +00:00
/* Attachments
$mail->AddAttachment("/var/tmp/file.tar.gz");
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
*/
2009-08-03 04:10:16 +00:00
if (! $mail->Send()) {
global $C_debug;
$C_debug->error(__FILE__,__METHOD__,sprintf('SMTP mail() failed to send message "%s" to "%s" on server "%s" (%s)',
$arr['subject'],$arr['to_email'],$arr['server'],$mail->ErrorInfo));
if ($this->debug) {
echo 'Message was not sent <p>';
printf('Mailer Error: %s',$mail->ErrorInfo);
}
2009-08-03 04:10:16 +00:00
return false;
}
2009-08-03 04:10:16 +00:00
return true;
}
}
2009-08-03 04:10:16 +00:00
?>