ZF-3362: about BCC and TO in Zend_Mail_Transport_Sendmail

Issue Type: Docs: Problem Created: 2008-06-01T11:04:16.000+0000 Last Updated: 2009-12-14T14:19:28.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Bart McLeod ( Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Mail

Related issues: Attachments: - patch_ZF3362.diff


<pre class="highlight"> $mail->addTo('');

The above code snippet adds all three mail addresses to the TO field. $mail is an instance of Zend_Mail. I would expect the latter two to be added to BCC field.

I am using standard/trunk from svn at the time 1.5.2 is released.

NOTE: Applies to using IIS under VISTA with no explicit mail transport set.


Posted by Wil Sinclair (wil) on 2008-06-01T12:33:17.000+0000

Please evaluate and categorize as necessary.

Posted by Karl Mikkelsen (kingkarl85) on 2008-06-11T21:42:11.000+0000

To fix this problem

File: Zend/Mail.php

500 /** 501 * Return list of recipient email addresses 502 * 503 * @return array (of strings) 504 */ 505 public function getRecipients() 506 { 507 return $this->_to; 508// return array_keys($this->_recipients); 509 }

This returns all recipients by default comment out line 508 and replace with line 507 to only return those added in the two!!!

CC and BCC will still work as they are added to the headers which are still included.

Posted by Karl Mikkelsen (kingkarl85) on 2008-06-11T21:57:15.000+0000

Further Investigation found this is only happening on a windows machine IIS not on apache on linux

Posted by Bart McLeod ( on 2008-06-12T01:57:33.000+0000

I must add that in my case it happens on windows Vista BU using Apache and remote smtp server of ISP.

Posted by Karl Mikkelsen (kingkarl85) on 2008-06-12T17:03:02.000+0000

**** Ignore the last change as it ill muck up the function to find out what recipients are getting mail ****

Yeah you would be right Bart - This would happen on all Windows machines as it has to do with the way the built-in mail(); function works.

On windows it acts as a kind of smtp router - on linux it is a direct hook into the sendmail MTA.

So there is a fundamental difference in the two and hence why the bug only turns up on a windows installation.

The following fix only puts the "To" recipients to the $to; in mail(); and all the Bcc and Cc are still added to the headers to they still get the email!!!!!

Change file....

File: Zend/Mail/Transport/Abstract.php

// Determine recipients, and prepare headers REMOVE THIS LINE // $this->recipients = implode(',', $mail->getRecipients()); /** This is the old code which gets all recipients and adds them to the "to" in mail() - this is not good */

ADD THIS LINE $this->recipients = implode(',', $mail->getTo()); // now you only get the _to recipients to add to the to in mail()

$this->_prepareHeaders($this->_getHeaders($boundary)); //All Bcc and Cc are still added as they are added in the headers where they belong

Add this function to...

File: Zend/Mail.php

/** * Return list of "To" recipient email addresses only, this ignore's the Cc and Bcc * * @return array (of strings) */ public function getTo() { return $this->_to; }

This is a better fix!!!!!!!! - Same basic idea though

Posted by Nico Edtinger (nico) on 2008-06-18T10:59:31.000+0000

Am I right, that this only happens with the sendmail transport? mail() has a different behavior under Windows. Have you tried using Zend_Mail_Transport_Smtp? Does it have similar problems?

I currently don't have a Windows with PHP here, so if anyone is faster than me providing a patch ... But recipients and the to header are two different things. The recipients are used for the envelope and if you replace it with what's in the to header you might break the SMTP transport. There is already special treatment for Windows in Zend_Mail_Transport_Sendmail::_prepareHeaders() and if there's something that should be fixed it's in this method.

Posted by Bart McLeod ( on 2008-06-18T12:41:07.000+0000

I must admit that I did not look into transport at all. I have seen it come by when reading about Zend_Mail, but I thought, well, if it wraps mail(), it will work, since mail() works. This basically means that I did not set the transport explicitly, so I am using the default behavior under windows.

To me personally it doesn't really matter if it gets fixed fast, my production server being linux.

I tried the transport just now, to be sure if it makes a difference, and yes, it does, under windows using new Zend_Mail_Transport_Smtp('') works as it should!

So I guess it may come down to choosing the right transport for the job. The only downside I can see is that I will now have to configure the smtp server for the live host and the local testserver. But that's no big deal.

Posted by Bart McLeod ( on 2008-06-18T12:43:25.000+0000

Changed priority to minor, because it works under windows if you use Zend_Mail_Transport_Smtp.

Posted by old of Satoru Yoshida ( on 2009-01-03T17:30:33.000+0000

Change summary to be more understandable easyly

Posted by Bart McLeod ( on 2009-01-04T01:31:08.000+0000

Changed summary.

Posted by Benjamin Eberlei (beberlei) on 2009-09-18T04:52:49.000+0000

I'll close this as documentation related issue, since this is also stated in the PHP manual and stuff.

A passage will be added to the documentation and i'll close, any comments?

Posted by Benjamin Eberlei (beberlei) on 2009-09-18T11:21:11.000+0000

Fixed as documentation issue

Posted by Bart McLeod ( on 2009-09-24T01:52:15.000+0000

Well done.

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.