/** 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; }
$arr_header = array("Reply-To: " . $row["vDeptMail"]); if ($var_cc != "") { // $Headers.="Bcc: $var_cc\r\n"; $arr_header[] = "Bcc: {$var_cc}"; } //$Headers.="MIME-Version: 1.0\n"; //$Headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; //$mailstatus=@mail($var_email,$var_subject,$var_body,$Headers); $mime = new MIME_mail($row["vDeptMail"], $var_email, $var_subject, $var_body, $arr_header); //$mime->fattach($fname, "Resume of $name", $type); // echo "<br>varuploadfiles(3)==".$var_uploaded_files; if ($var_uploaded_files != "") { $vAttacharr = explode("|", $var_uploaded_files); foreach ($vAttacharr as $key => $value) { $split_name_url = explode("*", $value); $mime->fattach("../attachments/" . $split_name_url[0], "Attached here is " . $split_name_url[1]); } } $mime->send_mail(); } //insert into reply table $sql = "insert into sptbl_replies(nReplyId,nTicketId,nStaffId,vStaffLogin,"; $sql .= " dDate,tReply,tPvtMessage,vReplyTime,vMachineIP) values('','" . mysql_real_escape_string($var_tid) . "',"; $sql .= "'" . mysql_real_escape_string($_SESSION["sess_staffid"]) . "',"; $sql .= "'" . mysql_real_escape_string($_SESSION["sess_staffname"]) . "',now(),'" . mysql_real_escape_string($var_replymatter) . "','" . mysql_real_escape_string($var_pvtmessage) . "',"; $sql .= "'" . mysql_real_escape_string($var_timespent) . "','" . mysql_real_escape_string(getClientIP()) . "')"; executeQuery($sql, $conn); $var_insert_id = mysql_insert_id($conn); //Insert the actionlog if (logActivity()) { $sql = "Insert into sptbl_actionlog(nALId,nStaffId,vAction,vArea,nRespId,dDate) Values('','" . $_SESSION["sess_staffid"] . "','" . TEXT_ADDITION . "','Reply','" . mysql_real_escape_string($var_insert_id) . "',now())";
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 } if (preg_match("!/x\\-.+!i", $attachmenttype)) { $type = OCTET; } else { $type = str_replace("\n", "", $attachmenttype); } $disp = "attachment; filename=\"{$name}\"; name=\"{$name}\";"; $mime->fattach($filename, "Attachment for incident {$id}", $type, 'base64', $disp); } // Lookup the email template (we need this to find out if the update should be visible or not) $sql = "SELECT * FROM `{$dbEmailTemplates}` WHERE id='{$emailtype}' "; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } if (mysql_num_rows($result) < 1) { trigger_error("Email template '{$meailtype}' not found", E_USER_WARNING); } $emailtype = mysql_fetch_object($result); // actually send the email $mailok = $mime->send_mail(); if ($mailok == FALSE) { trigger_error("Internal error sending email: send_mail() failed", E_USER_WARNING);