ZF-3689: Recycle a Zend_Mail object and allow setting a new from

Issue Type: Improvement Created: 2008-07-19T14:51:53.000+0000 Last Updated: 2012-03-26T08:38:13.000+0000 Status: Resolved Fix version(s): - 1.7.3 (19/Jan/09)

Reporter: Till Klampaeckel (till) Assignee: Satoru Yoshida (satoruyoshida) Tags: - Zend_Mail

Related issues: - ZF-1626



<pre class="highlight">
     * Sets From-header and sender of the message
     * @param  string    $email
     * @param  string    $name
     * @return Zend_Mail Provides fluent interface
     * @throws Zend_Mail_Exception if called subsequent times
    public function setFrom($email, $name = '')
        if ($this->_from === null) {
            $email = strtr($email,"\r\n\t",'???');
            $this->_from = $email;
            $this->_storeHeader('From', $this->_encodeHeader('"'.$name.'"').' <'.$email.'>', true);
        } else {
             * @see Zend_Mail_Exception
            require_once 'Zend/Mail/Exception.php';
            throw new Zend_Mail_Exception('From Header set twice');
        return $this;

Currently it will always throw an exception. I don't see why I cannot set another from if I am try to send out multiple emails in a single run but with different froms.


Posted by Till Klampaeckel (till) on 2008-07-20T23:41:02.000+0000

I managed to get around this issue by extending Zend_Mail, added my own methods for setFrom() and setSubject. In setFrom, you have to make sure to also unset $this->_headers['From'], otherwise your email ends up with two From headers, which also works, but some MUAs screw up.

It would be nice if this made it into Zend_Mail though, I can provide patches if wanted.

Posted by old of Satoru Yoshida ( on 2009-01-03T04:01:37.000+0000

I think it depends on ZF-1626

Posted by old of Satoru Yoshida ( on 2009-01-03T04:29:26.000+0000

I think clearFrom() function will solve your problem.

I add the function at SVN r13499 .

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.