/** * Attaches files to mail * * @param CMIMEMail $mailer * @param string $body * @param string|array $types * @return string */ function nc_mail_attachment_attach(CMIMEMail $mailer, $body, $types) { $nc_core = nc_Core::get_object(); $db = $nc_core->db; $types_escaped = array(); if (!is_array($types)) { $types = array($types); } foreach ($types as $type) { $types_escaped[] = '\'' . $db->escape($type) . '\''; } $sql = "SELECT `Filename`, `Path`, `Content_Type`, `Extension` FROM `Mail_Attachment` WHERE `Type` IN (" . implode(',', $types_escaped) . ")"; $attachments = (array) $db->get_results($sql, ARRAY_A); while (preg_match('/\\%FILE_([-_a-z0-9]+)/i', $body, $match)) { $filename = $match[1]; $file = false; foreach ($attachments as $index => $attachment) { if (strtolower($attachment['Filename']) == strtolower($filename)) { $file = $attachment; unset($attachments[$index]); break; } } $replace = ''; if ($file) { $absolute_path = $nc_core->DOCUMENT_ROOT . $file['Path']; $replace = 'cid:' . $mailer->attachFileEmbed($absolute_path, $filename . '.' . $file['Extension'], $file['Content_Type']); } $body = preg_replace('/\\%FILE_' . preg_quote($filename) . '/', $replace, $body); } foreach ($attachments as $attachment) { $absolute_path = $nc_core->DOCUMENT_ROOT . $attachment['Path']; $mailer->attachFileEmbed($absolute_path, $attachment['Filename'] . '.' . $attachment['Extension'], $attachment['Content_Type']); } return $body; }
function SendMessage($PermissionGroupID, $Subject, $Message, $Attach, $is_html = 0) { global $db, $nc_core, $ROOT_FOLDER, $INCLUDE_FOLDER; global $FileToAttach, $FileToAttach_name, $FileToAttach_type; global $SPAM_FROM, $SPAM_FROM_NAME; global $systemTableID, $systemMessageID, $systemTableName; global $srchPat; require_once $INCLUDE_FOLDER . "s_files.inc.php"; require $ROOT_FOLDER . "message_fields.php"; require_once $INCLUDE_FOLDER . "s_list.inc.php"; $search_params = getSearchParams($fld, $fldType, $fldDoSearch, $srchPat); $fullSearchStr = $search_params[query]; $MyEmail = "info@" . $HTTP_DOMAIN; $MyName = "Supervisor"; $SPAM_MAIL = $nc_core->get_settings('UserEmailField'); if (!$SPAM_MAIL) { nc_print_status(CONTROL_USER_MAIL_ERROR_EMAILFIELD, 'error'); return; } $select = "SELECT `" . $SPAM_MAIL . "`\n FROM `User` AS a,\n `User_Group` AS ug\n WHERE a.`User_ID` > 0\n AND ug.`User_ID` = a.`User_ID`\n AND a.`" . $SPAM_MAIL . "` <> ''\n " . ($PermissionGroupID ? " AND ug.`PermissionGroup_ID` = " . intval($PermissionGroupID) : "") . $fullSearchStr . "\n ORDER BY a.`" . $SPAM_MAIL . "`"; if ($Result = $db->get_results($select, ARRAY_N)) { foreach ($Result as $Array) { $Email[] = $Array[0]; } $Email = array_unique($Email); } $m = new CMIMEMail(); $m->mailbody(strip_tags($Message), $is_html ? $Message : ''); if ($Attach) { $FileToAttach_name = $_FILES['FileToAttach']['name']; $FileToAttach_type = $_FILES['FileToAttach']['type']; $m->attachFile($_FILES['FileToAttach']['tmp_name'], $FileToAttach_name, $FileToAttach_type); } if (sizeof($Email)) { @set_time_limit(0); @ignore_user_abort(true); for ($i = 0; $i < sizeof($Email); $i++) { print $i + 1 . " . " . $Email[$i] . "<br>\n"; $m->send($Email[$i], $SPAM_FROM, $SPAM_FROM, $Subject, $SPAM_FROM_NAME); ob_flush(); flush(); } nc_print_status(CONTROL_USER_MAIL_OK, 'ok'); } else { nc_print_status(CONTROL_USER_MAIL_ERROR_NOONEEMAIL, 'error'); } return false; }