Add error checking for mail() function
authorSteve Sanbeg <sanbeg@users.mediawiki.org>
Thu, 12 Jul 2007 21:16:03 +0000 (21:16 +0000)
committerSteve Sanbeg <sanbeg@users.mediawiki.org>
Thu, 12 Jul 2007 21:16:03 +0000 (21:16 +0000)
includes/UserMailer.php

index eac8727..267a186 100644 (file)
@@ -180,19 +180,28 @@ function userMailer( $to, $from, $subject, $body, $replyto=null ) {
                set_error_handler( 'mailErrorHandler' );
                wfDebug( "Sending mail via internal mail() function\n" );
 
-               if (is_array($to))
-                       foreach ($to as $recip)
-                               mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers );
+               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
-                       mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers );
+                       $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 '';
                }
-               return $wgErrorString;
-       }
 }
 
 /**