- $wgErrorString = '';
- set_error_handler( 'mailErrorHandler' );
- wfDebug( "Sending mail via internal mail() function\n" );
-
- if (function_exists('mail'))
- if (is_array($to))
- foreach ($to as $recip)
- $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers );
- else
- $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers );
- else
- $wgErrorString = 'PHP is not configured to send mail';
-
-
- restore_error_handler();
-
- if ( $wgErrorString ) {
- wfDebug( "Error sending mail: $wgErrorString\n" );
- return $wgErrorString;
- } elseif (! $sent) {
- //mail function only tells if there's an error
- wfDebug( "Error sending mail\n" );
- return 'mailer error';
- } else {
- return '';
+ wfDebug( "Sending mail via PEAR::Mail to $dest\n" );
+ $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
+ foreach ( $chunks as $chunk ) {
+ $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
+ if ( !$status->isOK() ) {
+ wfRestoreWarnings();
+ return $status;
+ }
+ }
+ wfRestoreWarnings();
+ return Status::newGood();
+ } 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)
+
+ # Line endings need to be different on Unix and Windows due to
+ # the bug described at http://trac.wordpress.org/ticket/2603
+ if ( wfIsWindows() ) {
+ $body = str_replace( "\n", "\r\n", $body );
+ $endl = "\r\n";
+ } else {
+ $endl = "\n";
+ }
+ $ctype = ( is_null( $contentType ) ?
+ 'text/plain; charset=' . $wgOutputEncoding : $contentType );
+ $headers =
+ "MIME-Version: 1.0$endl" .
+ "Content-type: $ctype$endl" .
+ "Content-Transfer-Encoding: 8bit$endl" .
+ "X-Mailer: MediaWiki mailer$endl" .
+ 'From: ' . $from->toString();
+ if ( $replyto ) {
+ $headers .= "{$endl}Reply-To: " . $replyto->toString();
+ }
+
+ wfDebug( "Sending mail via internal mail() function\n" );
+
+ self::$mErrorString = '';
+ $html_errors = ini_get( 'html_errors' );
+ ini_set( 'html_errors', '0' );
+ set_error_handler( array( 'UserMailer', 'errorHandler' ) );
+
+ if ( is_array( $to ) ) {
+ foreach ( $to as $recip ) {
+ $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
+ }
+ } else {
+ $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
+ }
+
+ restore_error_handler();
+ ini_set( 'html_errors', $html_errors );
+
+ if ( self::$mErrorString ) {
+ wfDebug( "Error sending mail: " . self::$mErrorString . "\n" );
+ return Status::newFatal( 'php-mail-error', self::$mErrorString );
+ } elseif ( ! $sent ) {
+ // mail function only tells if there's an error
+ wfDebug( "Error sending mail\n" );
+ return Status::newFatal( 'php-mail-error-unknown' );
+ } else {
+ return Status::newGood();
+ }