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

Issue Type: Bug Created: 2009-12-08T01:03:50.000+0000 Last Updated: 2009-12-24T02:25:32.000+0000 Status: Resolved Fix version(s): - 1.9.7 (11/Jan/10)

Reporter: R Slootjes (rslootjes) Assignee: Satoru Yoshida (satoruyoshida) Tags: - Zend_Mail

Related issues: Attachments:


The _sendMail() function doesnt check if mail() is actually available. When I run it on my local XAMPP installation I don't have the mail-function available and it will return an error about that. If the mail would have the error surpressed I will get an exception. So, please place @'s before the mail() functions so I can catch the exception without getting extra errors/warnings. Simple fix I guess :)


Posted by Satoru Yoshida (satoruyoshida) on 2009-12-14T02:35:09.000+0000

Hi, R Slootjes.

In substitution for @ mark, could it also match Your purpose like as following code ?

<pre class="highlight">
if (function_exists('mail') === false) {
    require_once 'Zend/Mail/Transport/Exception.php';
    throw new Zend_Mail_Transport_Exception('Unable to use mail');

Posted by R Slootjes (rslootjes) on 2009-12-14T04:33:13.000+0000

That won't be sufficient since this:




The function exists but it's just not configured to work (i guess).

Posted by Satoru Yoshida (satoruyoshida) on 2009-12-14T06:05:29.000+0000

Thank You for responce, R Slootjes. Then I will be happy if you would try the following code.

<pre class="highlight">
//Add property
protected $_errstr;

public function _sendMail()
    //Add next line
    set_error_handler(array($this, '_handleSomeErrors'));
    if ($this->parameters === null) {
        $result = mail(
    } else {
        $result = mail(
    //Add next line

    //Change next line
    if ($this->_errstr !== null || !$result) {
        require_once 'Zend/Mail/Transport/Exception.php';
        //Change next argument
        throw new Zend_Mail_Transport_Exception('Unable to send mail:' . $this->_errstr);

//Add function
protected function _handleSomeErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
    $this->_errstr = $errstr;
    return true;

Posted by R Slootjes (rslootjes) on 2009-12-16T03:28:39.000+0000

I will try to test this today, i just got some tight deadlines ;)

Posted by R Slootjes (rslootjes) on 2009-12-17T01:21:25.000+0000

This seems to be working like it should:

<pre class="highlight">
    $objMail = new Zend_Mail();


    $objMail->setFrom('', 'Robert');
    $objMail->addTo('', 'Robert');
catch(Exception $objException)
    echo 'exception: ' . $objException->getMessage();


<pre class="highlight">
exception: Unable to send mail:mail() [<a href="function.mail">function.mail</a>]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

Posted by Satoru Yoshida (satoruyoshida) on 2009-12-17T07:20:26.000+0000

Thank You for cooperation, R Slootjes ;-) I reflected it at SVN trunk r19712.

Posted by Satoru Yoshida (satoruyoshida) on 2009-12-24T02:25:32.000+0000

change to next mini. SVN r19915 in 1.9 branch

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.