Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

UserMailer.php

Go to the documentation of this file.
00001 <?php 00002 00003 # This function will perform a direct (authenticated) login to 00004 # a SMTP Server to use for mail relaying if 'wgSMTP' specifies an 00005 # array of parameters. It requires PEAR:Mail to do that. 00006 # Otherwise it just uses the standard PHP 'mail' function. 00007 function userMailer( $to, $from, $subject, $body ) 00008 { 00009 global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString; 00010 00011 $qto = wfQuotedPrintable( $to ); 00012 00013 if (is_array( $wgSMTP )) 00014 { 00015 require_once( "Mail.php" ); 00016 00017 $timestamp = time(); 00018 00019 $headers["From"] = $from; 00020 /* removing to: field as it should be set by the send() function below 00021 UNTESTED - Hashar */ 00022 // $headers["To"] = $qto; 00023 $headers["Subject"] = $subject; 00024 $headers["MIME-Version"] = "1.0"; 00025 $headers["Content-type"] = "text/plain; charset={$wgOutputEncoding}"; 00026 $headers["Content-transfer-encoding"] = "8bit"; 00027 $headers["Message-ID"] = "<{$timestamp}" . $wgUser->getName() . "@" . $wgSMTP["IDHost"] . ">"; 00028 $headers["X-Mailer"] = "MediaWiki interuser e-mailer"; 00029 00030 // Create the mail object using the Mail::factory method 00031 $mail_object =& Mail::factory("smtp", $wgSMTP); 00032 00033 $mailResult =& $mail_object->send($to, $headers, $body); 00034 00035 # Based on the result return an error string, 00036 if ($mailResult === true) 00037 return ""; 00038 else if (is_object($mailResult)) 00039 return $mailResult->getMessage(); 00040 else 00041 return "Mail object return unknown error."; 00042 } 00043 00044 else 00045 { 00046 $headers = 00047 "MIME-Version: 1.0\r\n" . 00048 "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" . 00049 "Content-transfer-encoding: 8bit\r\n" . 00050 "From: {$from}\r\n" . 00051 "Reply-To: {$from}\r\n" . 00052 "X-Mailer: MediaWiki interuser e-mailer"; 00053 00054 $wgErrorString = ""; 00055 set_error_handler( "mailErrorHandler" ); 00056 mail( $to, $subject, $body, $headers ); 00057 restore_error_handler(); 00058 00059 return $wgErrorString; 00060 } 00061 } 00062 00063 function mailErrorHandler( $code, $string ) { 00064 global $wgErrorString; 00065 $wgErrorString = preg_replace( "/^mail\(\): /", "", $string ); 00066 } 00067 00068 ?>

Generated on Tue Jun 29 23:40:07 2004 for Mediawiki by doxygen 1.3.7