3 # This function will perform a direct (authenticated) login to
4 # a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
5 # array of parameters. It requires PEAR:Mail to do that.
6 # Otherwise it just uses the standard PHP 'mail' function.
7 function userMailer( $to, $from, $subject, $body )
9 global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString;
11 $qto = wfQuotedPrintable( $to );
13 if (is_array( $wgSMTP ))
15 require_once( 'Mail.php' );
19 $headers['From'] = $from;
20 /* removing to: field as it should be set by the send() function below
22 // $headers["To"] = $qto;
23 $headers['Subject'] = $subject;
24 $headers['MIME-Version'] = '1.0';
25 $headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
26 $headers['Content-transfer-encoding'] = '8bit';
27 $headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>';
28 $headers['X-Mailer'] = 'MediaWiki interuser e-mailer';
30 // Create the mail object using the Mail::factory method
31 $mail_object =& Mail
::factory('smtp', $wgSMTP);
33 $mailResult =& $mail_object->send($to, $headers, $body);
35 # Based on the result return an error string,
36 if ($mailResult === true)
38 else if (is_object($mailResult))
39 return $mailResult->getMessage();
41 return 'Mail object return unknown error.';
47 "MIME-Version: 1.0\n" .
48 "Content-type: text/plain; charset={$wgOutputEncoding}\n" .
49 "Content-transfer-encoding: 8bit\n" .
51 "X-Mailer: MediaWiki interuser e-mailer";
54 set_error_handler( 'mailErrorHandler' );
55 mail( $to, $subject, $body, $headers );
56 restore_error_handler();
58 return $wgErrorString;
62 function mailErrorHandler( $code, $string ) {
63 global $wgErrorString;
64 $wgErrorString = preg_replace( "/^mail\(\): /", "", $string );