* @addtogroup SpecialPage
*/
-require_once('UserMailer.php');
-
/**
* @todo document
*/
$mailResult = UserMailer::send( $to, $mailFrom, $subject, $this->text, $replyTo );
if( WikiError::isError( $mailResult ) ) {
- $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
+ $wgOut->addHTML( wfMsg( "usermailererror" ) .
+ ' ' . htmlspecialchars( $mailResult->getMessage() ) );
} else {
// if the user requested a copy of this mail, do this now,
if ($this->cc_me && $to != $from) {
$cc_subject = wfMsg('emailccsubject', $this->target->getName(), $subject);
if( wfRunHooks( 'EmailUser', array( &$from, &$from, &$cc_subject, &$this->text ) ) ) {
- $ccResult = userMailer( $from, $from, $cc_subject, $this->text );
+ $ccResult = UserMailer::send( $from, $from, $cc_subject, $this->text );
if( WikiError::isError( $ccResult ) ) {
// At this stage, the user's CC mail has failed, but their
// original mail has succeeded. It's unlikely, but still, what to do?
// We can either show them an error, or we can say everything was fine,
// or we can say we sort of failed AND sort of succeeded. Of these options,
// simply saying there was an error is probably best.
- $wgOut->addHTML( wfMsg( "usermailererror" ) . $ccResult);
+ $wgOut->addHTML( wfMsg( "usermailererror" ) .
+ ' ' . htmlspecialchars( $ccResult->getMessage() ) );
return;
}
}
*
* @param string $subject
* @param string $body
- * @param strong $from Optional from address; default $wgPasswordSender will be used otherwise.
+ * @param string $from Optional from address; default $wgPasswordSender will be used otherwise.
* @return mixed True on success, a WikiError object on failure.
*/
- function sendMail( $subject, $body, $from = null ) {
+ function sendMail( $subject, $body, $from = null, $replyto = null ) {
if( is_null( $from ) ) {
global $wgPasswordSender;
$from = $wgPasswordSender;
$to = new MailAddress( $this );
$sender = new MailAddress( $from );
- $error = UserMailer::send( $to, $sender, $subject, $body );
-
- if( $error == '' ) {
- return true;
- } else {
- return new WikiError( $error );
- }
+ return UserMailer::send( $to, $sender, $subject, $body, $replyto );
}
/**
*/
protected static function sendWithPear($mailer, $dest, $headers, $body)
{
- $mailResult =& $mailer->send($dest, $headers, $body);
+ $mailResult = $mailer->send($dest, $headers, $body);
# Based on the result return an error string,
- if ($mailResult === true) {
- return '';
- } elseif (is_object($mailResult)) {
+ if( PEAR::isError( $mailResult ) ) {
wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
- return $mailResult->getMessage();
+ return new WikiError( $mailResult->getMessage() );
} else {
- wfDebug( "PEAR::Mail failed, unknown error result\n" );
- return 'Mail object return unknown error.';
+ return true;
}
}
* @param $subject String: email's subject.
* @param $body String: email's text.
* @param $replyto String: optional reply-to email (default: null).
+ * @return mixed True on success, a WikiError object on failure.
*/
static function send( $to, $from, $subject, $body, $replyto=null ) {
global $wgSMTP, $wgOutputEncoding, $wgErrorString, $wgEnotifImpersonal;
$mail_object =& Mail::factory('smtp', $wgSMTP);
if( PEAR::isError( $mail_object ) ) {
wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
- return $mail_object->getMessage();
+ return new WikiError( $mail_object->getMessage() );
}
wfDebug( "Sending mail via PEAR::Mail to $dest\n" );
- if (is_array($dest)) {
- $chunks = array_chunk($dest, $wgEnotifMaxRecips);
- foreach ($chunks as $chunk) {
- $e = self::sendWithPear($mail_object, $chunk, $headers, $body);
- if ($e != '')
- return $e;
- }
- } else
- return $mail_object->send($dest, $headers, $body);
-
+ $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
+ foreach ($chunks as $chunk) {
+ $e = self::sendWithPear($mail_object, $chunk, $headers, $body);
+ if( WikiError::isError( $e ) )
+ return $e;
+ }
} else {
# In the following $headers = expression we removed "Reply-To: {$from}\r\n" , because it is treated differently
# (fifth parameter of the PHP mail function, see some lines below)
if ( $wgErrorString ) {
wfDebug( "Error sending mail: $wgErrorString\n" );
- return $wgErrorString;
+ return new WikiError( $wgErrorString );
} elseif (! $sent) {
//mail function only tells if there's an error
wfDebug( "Error sending mail\n" );
- return 'mailer error';
+ return new WikiError( 'mailer error' );
} else {
- return '';
+ return true;
}
}
}
function userMailer( $to, $from, $subject, $body, $replyto=null ) {
return UserMailer::send( $to, $from, $subject, $body, $replyto );
}
-
-
-