예제 #1
0
/**
 *
 * @author Paul Heaney
 * @todo TODO document this
*/
function saction_MailPreviousMonthsTransactions()
{
    global $CONFIG;
    /*
         Get todays date
         Subtract one from the month and find last month
         Find the last day of last month
         fope(transactions.php?mode=csv&start=X&end=Y&breakdonw=yes
         mail to people
     TODO need a mechanism to subscribe to scheduled events? Could this be done with a trigger? Hmmhhhhhh
    */
    $currentmonth = date('m');
    $currentyear = date('y');
    if ($currentmonth == 1) {
        $currentyear--;
        $lastmonth = 12;
    } else {
        $lastmonth = $currentmonth - 1;
    }
    $startdate = "{$currentyear}-{$lastmonth}-01";
    // Find last date of previous month, 5 day an arbitary choice
    $lastday = date('t', strtotime('{$currentyear}-{$lastmonth}-05'));
    $enddate = "{$currentyear}-{$lastmonth}-{$lastday}";
    $csv = transactions_report('', $startdate, $enddate, '', 'csv', TRUE);
    $extra_headers = "Reply-To: {$CONFIG['support_email']}\nErrors-To: {$CONFIG['support_email']}\n";
    // TODO should probably be different
    $extra_headers .= "X-Mailer: {$CONFIG['application_shortname']} {$application_version_string}/PHP " . phpversion() . "\n";
    $extra_headers .= "X-Originating-IP: {$_SERVER['REMOTE_ADDR']}\n";
    //    if ($ccfield != '')  $extra_headers .= "cc: $ccfield\n";
    //    if ($bccfield != '') $extra_headers .= "Bcc: $bccfield\n";
    $extra_headers .= "\n";
    // add an extra crlf to create a null line to separate headers from body
    // this appears to be required by some email clients - INL
    $subject = sprintf($GLOBALS['strBillableIncidentsForPeriodXtoX'], $startdate, $enddate);
    $bodytext = $GLOBALS['strAttachedIsBillableIncidentsForAbovePeriod'];
    $mime = new MIME_mail($CONFIG['support_email'], $CONFIG['billing_reports_email'], html_entity_decode($subject), $bodytext, $extra_headers, '');
    $mime->attach($csv, "Billable report", OCTET, BASE64, "filename=billable_incidents_{$lastmonth}_{$currentyear}.csv");
    return $mime->send_mail();
}
예제 #2
0
/**
    Send a template email without using a trigger
    @author Ivan Lucas
    @param int $templateid: The ID number of the template to use
    @param array $paramarray. An associative array of template parameters
                 This should at the very least be
                 array('incidentid' => $id, 'triggeruserid' => $sit[2])
    @param string $attach. Path and filename of file to attach
    @param string $attachtype. Type of file to attach (Default 'OCTET')
    @param string $attachdesc. Description of the attachment, (Default, same as filename)
    @retval bool TRUE: The email was sent successfully
    @retval bool FALSE: There was an error sending the mail
    @note This is v2 of this function, it has different paramters than v1
**/
function send_email_template($templateid, $paramarray, $attach = '', $attachtype = '', $attachdesc = '')
{
    global $CONFIG, $application_version_string, $sit;
    if (!is_array($paramarray)) {
        trigger_error("Invalid Parameter Array", E_USER_NOTICE);
        $paramarray = array('triggeruserid' => $sit[2]);
    }
    if (!is_numeric($templateid)) {
        trigger_error("Invalid Template ID '{$templateid}'", E_USER_NOTICE);
    }
    // Grab the template
    $tsql = "SELECT * FROM `{$dbEmailTemplates}` WHERE id={$templateid} LIMIT 1";
    $tresult = mysql_query($tsql);
    if (mysql_error()) {
        trigger_error(mysql_error(), E_USER_WARNING);
    }
    if (mysql_num_rows($tresult) > 0) {
        $template = mysql_fetch_object($tresult);
    }
    $paramarray = array('incidentid' => $paramarray['incidentid'], 'triggeruserid' => $sit[2]);
    $from = replace_specials($template->fromfield, $paramarray);
    $replyto = replace_specials($template->replytofield, $paramarray);
    $ccemail = replace_specials($template->ccfield, $paramarray);
    $bccemail = replace_specials($template->bccfield, $paramarray);
    $toemail = replace_specials($template->tofield, $paramarray);
    $subject = replace_specials($template->subjectfield, $paramarray);
    $body = replace_specials($template->body, $paramarray);
    $extra_headers = "Reply-To: {$replyto}\nErrors-To: " . user_email($sit[2]) . "\n";
    $extra_headers .= "X-Mailer: {$CONFIG['application_shortname']} {$application_version_string}/PHP " . phpversion() . "\n";
    $extra_headers .= "X-Originating-IP: {$_SERVER['REMOTE_ADDR']}\n";
    if ($ccemail != '') {
        $extra_headers .= "CC: {$ccemail}\n";
    }
    if ($bccemail != '') {
        $extra_headers .= "BCC: {$bccemail}\n";
    }
    $extra_headers .= "\n";
    // add an extra crlf to create a null line to separate headers from body
    // this appears to be required by some email clients - INL
    // Removed $mailerror as MIME_mail expects 5 args and not 6 of which is it not expect errors
    $mime = new MIME_mail($from, $toemail, html_entity_decode($subject), '', $extra_headers);
    $mime->attach($body, '', "text-plain; charset={$GLOBALS['i18ncharset']}", 'quoted-printable');
    if (!empty($attach)) {
        if (empty($attachdesc)) {
            $attachdesc = "Attachment named {$attach}";
        }
        $disp = "attachment; filename=\"{$attach}\"; name=\"{$attach}\";";
        $mime->fattach($attach, $attachdesc, $attachtype, 'base64', $disp);
    }
    // actually send the email
    $rtnvalue = $mime->send_mail();
    return $rtnvalue;
}
예제 #3
0
 if ($errors == 0) {
     $extra_headers = "Reply-To: {$replytofield}\nErrors-To: " . user_email($sit[2]) . "\n";
     $extra_headers .= "X-Mailer: {$CONFIG['application_shortname']} {$application_version_string}/PHP " . phpversion() . "\n";
     $extra_headers .= "X-Originating-IP: {$_SERVER['REMOTE_ADDR']}\n";
     if ($ccfield != '') {
         $extra_headers .= "CC: {$ccfield}\n";
     }
     if ($bccfield != '') {
         $extra_headers .= "BCC: {$bccfield}\n";
     }
     $extra_headers .= "\n";
     // add an extra crlf to create a null line to separate headers from body
     // this appears to be required by some email clients - INL
     $mime = new MIME_mail($fromfield, $tofield, html_entity_decode($subjectfield), '', $extra_headers, $mailerror);
     // INL 5 Aug 09, quoted-printable seems to split lines in unexpected places, base64 seems to work ok
     $mime->attach($bodytext, 'bodytext', "text/plain; charset={$GLOBALS['i18ncharset']}", 'quoted-printable', 'inline');
     // check for attachment
     //        if ($_FILES['attachment']['name']!='' || strlen($filename) > 3)
     if ($filename != '' && strlen($filename) > 3) {
         //          if (!isset($filename)) $filename = $attachment_fspath.$_FILES['attachment']['name'];   ??? TPG 13/08/2002
         if (!file_exists($filename)) {
             trigger_error("File did not exist upon processing attachment: {$filename}", E_USER_WARNING);
         }
         if ($filename == '') {
             trigger_error("Filename was blank upon processing attachment: {$filename}", E_USER_WARNING);
         }
         // Check file size before sending
         if (filesize($filename) > $CONFIG['upload_max_filesize'] || filesize($filename) == FALSE) {
             trigger_error("User Error: Attachment too large or file upload error, filename: {$filename},  perms: " . fileperms($filename) . ", size:", filesize($filename), E_USER_WARNING);
             // throwing an error isn't the nicest thing to do for the user but there seems to be no way of
             // checking file sizes at the client end before the attachment is uploaded. - INL