]> git.mxchange.org Git - mailer.git/commitdiff
Added missing email-functions.php :(
authorRoland Häder <roland@mxchange.org>
Sat, 29 Sep 2012 12:52:18 +0000 (12:52 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 29 Sep 2012 12:52:18 +0000 (12:52 +0000)
.gitattributes
inc/config-global.php
inc/email-functions.php [new file with mode: 0644]

index 0600d9c829d06cb0d50763e248feba177448d62f..e0acc3d33564f30ace7bb244a828d4c9df6919d7 100644 (file)
@@ -130,6 +130,7 @@ inc/debug/client/.htaccess svneol=native#text/plain
 inc/debug/relay/.htaccess svneol=native#text/plain
 inc/debug/request_ svneol=native#text/plain
 inc/debug/server/.htaccess svneol=native#text/plain
 inc/debug/relay/.htaccess svneol=native#text/plain
 inc/debug/request_ svneol=native#text/plain
 inc/debug/server/.htaccess svneol=native#text/plain
+inc/email-functions.php -text
 inc/expression-functions.php svneol=native#text/plain
 inc/extensions-functions.php svneol=native#text/plain
 inc/extensions/.htaccess svneol=native#text/plain
 inc/expression-functions.php svneol=native#text/plain
 inc/extensions-functions.php svneol=native#text/plain
 inc/extensions/.htaccess svneol=native#text/plain
index f2ef6fd7fcd75cb03a0b10a17203897603d13428..6fba83c71e1bca519f3fd36a07ac674cf5e1405a 100644 (file)
@@ -63,7 +63,7 @@ if (function_exists('import_request_variables')) {
 $path = str_replace(chr(92), '/', substr(dirname(__FILE__), 0, -3));
 
 // Some very important function includes
 $path = str_replace(chr(92), '/', substr(dirname(__FILE__), 0, -3));
 
 // Some very important function includes
-foreach (array('config', 'wrapper', 'template', 'module', 'inc', 'stats', 'http', 'xml', 'callback', 'referral') as $inc) {
+foreach (array('config', 'wrapper', 'template', 'module', 'inc', 'stats', 'http', 'xml', 'callback', 'referral', 'email') as $inc) {
        include($path . 'inc/' . $inc . '-functions.php');
 } // END - foreach
 
        include($path . 'inc/' . $inc . '-functions.php');
 } // END - foreach
 
diff --git a/inc/email-functions.php b/inc/email-functions.php
new file mode 100644 (file)
index 0000000..ced06aa
--- /dev/null
@@ -0,0 +1,227 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 07/01/2012 *
+ * ===================                          Last change: 07/01/2012 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : email-functions.php                              *
+ * -------------------------------------------------------------------- *
+ * Short description : Email-delivery-related functions                 *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Mailversand bezogene Funktionen                  *
+ * -------------------------------------------------------------------- *
+ * $Revision:: 2773                                                   $ *
+ * $Date:: 2012-06-26 01:02:44 +0200 (Tue, 26 Jun 2012)               $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author:: quix0r                                                   $ *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
+ *                                                                      *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with this program; if not, write to the Free Software          *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
+ * MA  02110-1301  USA                                                  *
+ ************************************************************************/
+
+// Some security stuff...
+if (!defined('__SECURITY')) {
+       die();
+} // END - if
+
+// Send mail out to an email address
+function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '') {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'toEmail=' . $toEmail . ',subject=' . $subject . ',isHtml=' . $isHtml);
+       // Empty parameters should be avoided, so we need to find them
+       if (empty($isHtml)) {
+               // isHtml is empty
+               reportBug(__FUNCTION__, __LINE__, 'isHtml is empty.');
+       } // END - if
+
+       // Set from header
+       if ((!isInString('@', $toEmail)) && ($toEmail > 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 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('<pre>
+<strong>Headers</strong> : ' . htmlentities(trim($mailHeader)) . '
+<strong>To</strong>      : ' . htmlentities($toEmail) . '
+<strong>Subject</strong> : ' . htmlentities($subject) . '
+<strong>Message(' . strlen($message) . ')</strong> : ' . htmlentities($message) . '
+</pre>');
+
+               // 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'));
+       }
+}
+
+// ----------------------------------------------------------------------------
+//                           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]
+?>