+ if ( $wgEnotifImpersonal ) {
+ $headers['To'] = 'undisclosed-recipients:;';
+ }
+ else {
+ $headers['To'] = implode( ", ", (array )$dest );
+ }
+
+ if ( $replyto ) {
+ $headers['Reply-To'] = $replyto->toString();
+ }
+ $headers['Subject'] = self::quotedPrintable( $subject );
+ $headers['Date'] = date( 'r' );
+ $headers['MIME-Version'] = '1.0';
+ $headers['Content-type'] = ( is_null( $contentType ) ?
+ 'text/plain; charset=' . $wgOutputEncoding : $contentType );
+ $headers['Content-transfer-encoding'] = '8bit';
+ $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>'; // FIXME
+ $headers['X-Mailer'] = 'MediaWiki mailer';
+
+ wfSuppressWarnings();
+
+ // Create the mail object using the Mail::factory method
+ $mail_object =& Mail::factory( 'smtp', $wgSMTP );
+ if ( PEAR::isError( $mail_object ) ) {
+ wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
+ wfRestoreWarnings();
+ return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
+ }
+
+ 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' ) );
+
+ // We need to check for safe_mode, because mail() throws an E_NOTICE
+ // on the 5th parameter when it's turned on
+ $sm = wfIniGetBool( 'safe_mode' );
+
+ if ( !is_array( $to ) ) {
+ $to = array( $to );
+ }
+ foreach ( $to as $recip ) {
+ if( $sm ) {
+ $sent = mail( $recip->toString(), self::quotedPrintable( $subject ), $body, $headers );
+ } else {
+ $sent = mail( $recip->toString(), self::quotedPrintable( $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();
+ }