2004-02-28 07:08:13 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Provide mail capabilities
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-02-27 12:48:07 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* 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 ) {
|
2004-04-01 13:05:20 +00:00
|
|
|
global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString;
|
2004-02-27 12:48:07 +00:00
|
|
|
|
|
|
|
|
$qto = wfQuotedPrintable( $to );
|
|
|
|
|
|
|
|
|
|
if (is_array( $wgSMTP ))
|
|
|
|
|
{
|
2004-08-22 17:24:50 +00:00
|
|
|
require_once( 'Mail.php' );
|
2004-02-27 12:48:07 +00:00
|
|
|
|
|
|
|
|
$timestamp = time();
|
|
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$headers['From'] = $from;
|
2004-05-20 03:04:14 +00:00
|
|
|
/* removing to: field as it should be set by the send() function below
|
|
|
|
|
UNTESTED - Hashar */
|
|
|
|
|
// $headers["To"] = $qto;
|
2004-08-22 23:32:05 +00:00
|
|
|
$headers['Subject'] = $subject;
|
2004-08-22 17:24:50 +00:00
|
|
|
$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';
|
2004-02-27 12:48:07 +00:00
|
|
|
|
|
|
|
|
// Create the mail object using the Mail::factory method
|
2004-08-22 17:24:50 +00:00
|
|
|
$mail_object =& Mail::factory('smtp', $wgSMTP);
|
2004-02-27 12:48:07 +00:00
|
|
|
|
|
|
|
|
$mailResult =& $mail_object->send($to, $headers, $body);
|
|
|
|
|
|
|
|
|
|
# Based on the result return an error string,
|
|
|
|
|
if ($mailResult === true)
|
2004-08-22 17:24:50 +00:00
|
|
|
return '';
|
2004-02-27 12:48:07 +00:00
|
|
|
else if (is_object($mailResult))
|
|
|
|
|
return $mailResult->getMessage();
|
|
|
|
|
else
|
2004-08-22 17:24:50 +00:00
|
|
|
return 'Mail object return unknown error.';
|
2004-02-27 12:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$headers =
|
2004-08-15 23:48:39 +00:00
|
|
|
"MIME-Version: 1.0\n" .
|
|
|
|
|
"Content-type: text/plain; charset={$wgOutputEncoding}\n" .
|
|
|
|
|
"Content-transfer-encoding: 8bit\n" .
|
|
|
|
|
"From: {$from}\n" .
|
2004-02-27 12:48:07 +00:00
|
|
|
"X-Mailer: MediaWiki interuser e-mailer";
|
2004-04-01 13:05:20 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgErrorString = '';
|
|
|
|
|
set_error_handler( 'mailErrorHandler' );
|
2004-02-27 12:48:07 +00:00
|
|
|
mail( $to, $subject, $body, $headers );
|
2004-04-01 13:05:20 +00:00
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
|
|
return $wgErrorString;
|
2004-02-27 12:48:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-04-01 13:05:20 +00:00
|
|
|
function mailErrorHandler( $code, $string ) {
|
|
|
|
|
global $wgErrorString;
|
|
|
|
|
$wgErrorString = preg_replace( "/^mail\(\): /", "", $string );
|
|
|
|
|
}
|
|
|
|
|
?>
|