0)) { // Does the user exist? if ((isExtensionActive('user')) && (fetchUserData($toEmail))) { // Get the email $toEmail = getUserData('email'); } else { // Set webmaster $toEmail = getWebmaster(); } } elseif (($toEmail == '0') || (is_null($toEmail))) { // Is the webmaster! $toEmail = getWebmaster(); } //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'TO=' . $toEmail); // Check for PHPMailer or debug-mode if ((!isPhpMailerConfigured()) || (isDebugModeEnabled())) { // Prefix is '' for text mails $prefix = ''; // Is HTML? if ($isHtml == 'Y') { // Set prefix $prefix = 'html_'; } // END - if // Load email header template $mailHeader = loadEmailTemplate($prefix . 'header', $mailHeader); } // END - if // Debug mode enabled? if (isDebugModeEnabled()) { // In debug mode we want to display the mail instead of sending it away so we can debug this part outputHtml('
Headers : ' . htmlentities(trim($mailHeader)) . ' To : ' . htmlentities($toEmail) . ' Subject : ' . htmlentities($subject) . ' Message(' . strlen($message) . ') : ' . htmlentities($message) . ''); // This is always fine return TRUE; } elseif (!empty($toEmail)) { // Send Mail away return sendRawEmail($toEmail, $subject, $message, $mailHeader); } elseif ($isHtml != 'Y') { // Problem detected while sending a mail, forward it to admin return sendRawEmail(getWebmaster(), '[PROBLEM:]' . $subject, $message, $mailHeader); } // Why did we end up here? This should not happen reportBug(__FUNCTION__, __LINE__, 'Ending up: template=' . $template); } /** * Check to use whether plain mail() command or PHPMailer class * @TODO Rewrite this to an extension 'smtp' * @private */ function isPhpMailerConfigured () { return ((getConfig('SMTP_HOSTNAME') != '') && (getConfig('SMTP_USER') != '')); } // Send out a raw email with PHPMailer class or plain mail() command function sendRawEmail ($toEmail, $subject, $message, $headers) { // Just compile all to put out all configs, etc. $eval = '$toEmail = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($toEmail), FALSE)) . '"); '; $eval .= '$subject = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($subject), FALSE)) . '"); '; $eval .= '$headers = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($headers), FALSE)) . '"); '; // Do not decode entities in the message because we also send HTML mails through this function $eval .= '$message = "' . escapeQuotes(doFinalCompilation(compileRawCode($message), FALSE)) . '";'; // Run the final eval() command eval($eval); // Shall we use PHPMailer class or plain mail() command? if (isPhpMailerConfigured()) { // Use PHPMailer class with SMTP enabled loadIncludeOnce('inc/phpmailer/class.phpmailer.php'); loadIncludeOnce('inc/phpmailer/class.smtp.php'); // get new instance $mail = new PHPMailer(); // Set charset to UTF-8 $mail->CharSet = 'UTF-8'; // Path for PHPMailer $mail->PluginDir = sprintf("%sinc/phpmailer/", getPath()); $mail->IsSMTP(); $mail->SMTPAuth = TRUE; $mail->Host = getConfig('SMTP_HOSTNAME'); $mail->Port = 25; $mail->Username = getConfig('SMTP_USER'); $mail->Password = getConfig('SMTP_PASSWORD'); if (empty($headers)) { $mail->From = getWebmaster(); } else { $mail->From = $headers; } $mail->FromName = getMainTitle(); $mail->Subject = $subject; if ((isExtensionActive('html_mail')) && (secureString($message) != $message)) { $mail->Body = $message; $mail->AltBody = decodeEntities($message); $mail->WordWrap = 70; $mail->IsHTML(TRUE); } else { $mail->Body = decodeEntities(strip_tags($message)); } $mail->AddAddress($toEmail, ''); $mail->AddReplyTo(getWebmaster(), getMainTitle()); $mail->AddCustomHeader('Errors-To: ' . getWebmaster()); $mail->AddCustomHeader('X-Loop: ' . getWebmaster()); $mail->AddCustomHeader('Bounces-To: ' . getWebmaster()); $mail->Send(); // Has an error occured? if (!empty($mail->ErrorInfo)) { // Log message logDebugMessage(__FUNCTION__, __LINE__, 'Error while sending mail: ' . $mail->ErrorInfo); // Raise an error return FALSE; } else { // All fine! return TRUE; } } else { // Use plain mail() command return mail($toEmail, $subject, decodeEntities($message), $headers); } } // Send notification to admin function sendAdminNotification ($subject, $templateName, $content = array(), $userid = NULL) { if ((isExtensionInstalledAndNewer('admins', '0.4.1')) && (function_exists('sendAdminsEmails'))) { // Send new way //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'admins=Y,subject=' . $subject . ',templateName=' . $templateName . ' - OKAY!'); sendAdminsEmails($subject, $templateName, $content, $userid); } else { // Send out-dated way //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'admins=N,subject=' . $subject . ',templateName=' . $templateName . ' - OUT-DATED!'); $message = loadEmailTemplate($templateName, $content, $userid); sendAdminEmails($subject, $message, ($templateName == 'admin_report_bug')); } } // Send mails for del/edit/lock build modes // @TODO $rawUserId is currently unused function sendGenericBuildMails ($mode, $tableName, $content, $id, $subjectPart = '', $userIdColumn = array('userid'), $rawUserId = array('userid')) { // $tableName must be an array if ((!is_array($tableName)) || (count($tableName) != 1)) { // $tableName is no array reportBug(__FUNCTION__, __LINE__, 'tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn); } elseif ((!is_array($userIdColumn)) || (count($userIdColumn) != 1)) { // $tableName is no array reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn); } // END - if // Default subject is the subject part $subject = $subjectPart; // Is the subject part not set? if (empty($subjectPart)) { // Then use it from the mode $subject = strtoupper($mode); } // END - if // Is the raw userid set? if (isValidUserId(postRequestElement($userIdColumn[0], $id))) { // Set it in content $content[$userIdColumn[0]] = bigintval(postRequestElement($userIdColumn[0], $id)); // Load email template if (!empty($subjectPart)) { $mail = loadEmailTemplate('member_' . $mode . '_' . strtolower($subjectPart) . '_' . $tableName[0], $content); } else { $mail = loadEmailTemplate('member_' . $mode . '_' . $tableName[0], $content); } // Send email out sendEmail(postRequestElement($userIdColumn[0], $id), strtoupper('{--MEMBER_' . $subject . '_' . $tableName[0] . '_SUBJECT--}'), $mail); } // END - if // Generate subject $subject = strtoupper('{--ADMIN_' . $subject . '_' . $tableName[0] . '_SUBJECT--}'); // Send admin notification out if (!empty($subjectPart)) { sendAdminNotification($subject, 'admin_' . $mode . '_' . strtolower($subjectPart) . '_' . $tableName[0], $content, postRequestElement($userIdColumn[0], $id)); } else { sendAdminNotification($subject, 'admin_' . $mode . '_' . $tableName[0], $content, postRequestElement($userIdColumn[0], $id)); } } // ---------------------------------------------------------------------------- // Template helper functions // ---------------------------------------------------------------------------- // Helper function to add extra headers to text mails function doTemplateAddExtraTextMailHeaders ($templateName, $clear, $extraHeaders = '') { // Run the header through the filter $extraHeaders = runFilterChain('add_extra_text_mail_headers', $extraHeaders); // And return it return $extraHeaders; } // Helper function to add extra headers to HTML mails function doTemplateAddExtraHtmlMailHeaders ($templateName, $clear, $extraHeaders = '') { // Run the header through the filter $extraHeaders = runFilterChain('add_extra_html_mail_headers', $extraHeaders); // And return it return $extraHeaders; } // [EOF] ?>