Scripts and data used for generating ZhConversion.php
[lhc/web/wiklou.git] / includes / UserMailer.php
index 6704a82..92b379d 100644 (file)
@@ -1,58 +1,68 @@
 <?php
+/**
+ * Provide mail capabilities
+ *
+ * @package MediaWiki
+ */
 
-# This function will perform a direct (authenticated) login to
-# a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
-# array of parameters. It requires PEAR:Mail to do that.
-# Otherwise it just uses the standard PHP 'mail' function.
-function userMailer( $to, $from, $subject, $body )
-{
+/**
+ * This function will perform a direct (authenticated) login to
+ * a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
+ * array of parameters. It requires PEAR:Mail to do that.
+ * Otherwise it just uses the standard PHP 'mail' function.
+ *
+ * @param string $to recipient's email
+ * @param string $from sender's email
+ * @param string $subject email's subject
+ * @param string $body email's text
+ */
+function userMailer( $to, $from, $subject, $body ) {
        global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString;
        
        $qto = wfQuotedPrintable( $to );
        
        if (is_array( $wgSMTP ))
        {
-               require_once( "Mail.php" );
+               require_once( 'Mail.php' );
                
                $timestamp = time();
        
-               $headers["From"] = $from;
+               $headers['From'] = $from;
 /* removing to: field as it should be set by the send() function below
    UNTESTED - Hashar */
 //             $headers["To"] = $qto;
-               $headers["Subject"] = $subject;
-               $headers["MIME-Version"] = "1.0";
-               $headers["Content-type"] = "text/plain; charset={$wgOutputEncoding}";
-               $headers["Content-transfer-encoding"] = "8bit";
-               $headers["Message-ID"] = "<{$timestamp}" . $wgUser->getName() . "@" . $wgSMTP["IDHost"] . ">";
-               $headers["X-Mailer"] = "MediaWiki interuser e-mailer";
+               $headers['Subject'] = $subject;
+               $headers['MIME-Version'] = '1.0';
+               $headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
+               $headers['Content-transfer-encoding'] = '8bit';
+               $headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>';
+               $headers['X-Mailer'] = 'MediaWiki interuser e-mailer';
        
                // Create the mail object using the Mail::factory method
-               $mail_object =& Mail::factory("smtp", $wgSMTP);
+               $mail_object =& Mail::factory('smtp', $wgSMTP);
        
                $mailResult =& $mail_object->send($to, $headers, $body);
                
                # Based on the result return an error string, 
                if ($mailResult === true)
-                       return "";
+                       return '';
                else if (is_object($mailResult))
                        return $mailResult->getMessage();
                else
-                       return "Mail object return unknown error.";
+                       return 'Mail object return unknown error.';
        }
        
        else
        {
                $headers =
-                       "MIME-Version: 1.0\r\n" .
-                       "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
-                       "Content-transfer-encoding: 8bit\r\n" .
-                       "From: {$from}\r\n" .
-                       "Reply-To: {$from}\r\n" .
+                       "MIME-Version: 1.0\n" .
+                       "Content-type: text/plain; charset={$wgOutputEncoding}\n" .
+                       "Content-transfer-encoding: 8bit\n" .
+                       "From: {$from}\n" .
                        "X-Mailer: MediaWiki interuser e-mailer";
 
-               $wgErrorString = "";
-               set_error_handler( "mailErrorHandler" );
+               $wgErrorString = '';
+               set_error_handler( 'mailErrorHandler' );
                mail( $to, $subject, $body, $headers );
                restore_error_handler();
 
@@ -60,9 +70,11 @@ function userMailer( $to, $from, $subject, $body )
        }
 }
 
+/**
+ *
+ */
 function mailErrorHandler( $code, $string ) {
        global $wgErrorString;
        $wgErrorString = preg_replace( "/^mail\(\): /", "", $string );
 }
-
 ?>