brettbrewer.com

Programming + Design

Home
Specifying Multiple recipients for Kohana's email helper library PDF Print E-mail
Written by Administrator   
Tuesday, 27 October 2009

I love the Kohana framework, but some of their docs are pretty bad. I've used it for months without knowing how to specify multiple recipients for the email::send() helper function which uses the SwiftMailer library. Today I looked at the source code and figured out how to specify multiple recipient addresses. Here's how:

$to = array(
     'to'=>array(' This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ','Recipient Name'),
     'to1'=>array(' This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ','Recipient1 Name'),
     'to2'=>array(' This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ','Recipient2 Name'),
     'cc'=>array('cc This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ','cc Recipient Name'),
     'bcc'=>array('bcc This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ','bcc Recipient Name')
);

$sentcount = email::send($to,$from,$subject,$body,true);

This assumes you've already set some vars for the $from address, message $subject, $body, etc. The trick to this is that Kohana's email::send() funtion will loop through your "to" array and anything that doesn't match the 'to','cc' or 'bcc' array keys will be sent as an additional "to" recipient. Even if you call the other keys "cc1","cc2", etc., the messages will be sent to them as primary recipients and their email address will show in the "to" field. There is no Kohana documentation anywhere to tell you this, so I hope this helps someone. 

Last Updated ( Tuesday, 27 October 2009 )
 
© 2010 www.brettbrewer.com
Joomla! is Free Software released under the GNU/GPL License.