From: Steve Sanbeg Date: Thu, 12 Jul 2007 21:16:03 +0000 (+0000) Subject: Add error checking for mail() function X-Git-Tag: 1.31.0-rc.0~52112 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=0ab7cfaab99936f3d4429888ecdaefccfba6d4af;p=lhc%2Fweb%2Fwiklou.git Add error checking for mail() function --- diff --git a/includes/UserMailer.php b/includes/UserMailer.php index eac8727c9b..267a186c83 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -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; - } } /**