Parcourir la source

[ZF-8493] Zend_Mail_Transport_Sendmail creates warning if it doesnt exist instead of throwing an exception

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19712 44c647ce-9c0f-0410-b52a-842ac1e357ba
yoshida@zend.co.jp il y a 16 ans
Parent
commit
8ad3dd3f8c
1 fichiers modifiés avec 26 ajouts et 4 suppressions
  1. 26 4
      library/Zend/Mail/Transport/Sendmail.php

+ 26 - 4
library/Zend/Mail/Transport/Sendmail.php

@@ -53,7 +53,6 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
      */
     public $parameters;
 
-
     /**
      * EOL character string
      * @var string
@@ -61,6 +60,11 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
      */
     public $EOL = PHP_EOL;
 
+    /**
+     * error information
+     * @var string
+     */
+    protected $_errstr;
 
     /**
      * Constructor.
@@ -83,6 +87,7 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
      */
     public function _sendMail()
     {
+        set_error_handler(array($this, '_handleMailErrors'));
         if ($this->parameters === null) {
             $result = mail(
                 $this->recipients,
@@ -97,12 +102,14 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
                 $this->header,
                 $this->parameters);
         }
-        if (!$result) {
+        restore_error_handler();
+
+        if ($this->_errstr !== null || !$result) {
             /**
              * @see Zend_Mail_Transport_Exception
              */
             require_once 'Zend/Mail/Transport/Exception.php';
-            throw new Zend_Mail_Transport_Exception('Unable to send mail');
+            throw new Zend_Mail_Transport_Exception('Unable to send mail. ' . $this->_errstr);
         }
     }
 
@@ -169,5 +176,20 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
         $this->header = rtrim($this->header);
     }
 
-}
+    /**
+     * Temporary error handler for PHP native mail().
+     *
+     * @param int    $errno
+     * @param string $errstr
+     * @param string $errfile
+     * @param string $errline
+     * @param array  $errcontext
+     * @return true
+     */
+    public function _handleMailErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
+    {
+        $this->_errstr = $errstr;
+        return true;
+    }
 
+}