@@ -34,7 +34,7 @@ class MandrillMailer extends DataObject implements MailerInterface
3434 *
3535 * @var string
3636 */
37- protected $ password ;
37+ protected $ apiKey ;
3838
3939 /**
4040 * List of errors
@@ -53,50 +53,32 @@ class MandrillMailer extends DataObject implements MailerInterface
5353 public function send (MailMessage $ message )
5454 {
5555 try {
56- $ mandrill = new Mandrill ($ this ->password );
56+ $ mandrill = new Mandrill ($ this ->apiKey );
5757
5858 $ mandrillMessage = array (
5959 'html ' => $ message ->getBody (),
60- 'text ' => 'Example text content ' ,
6160 'subject ' => $ message ->getSubject (),
6261 'from_email ' => $ message ->getFrom ()->getEmail (),
6362 'from_name ' => $ message ->getFrom ()->getName (),
6463 );
6564
6665 // Recipients.
67- if ($ to = $ message ->getTo ()) {
68- $ toArray = [];
69- foreach ($ to as $ address ) {
70- $ toArray [] = [
71- 'email ' => $ address ->getEmail (),
72- 'name ' => $ address ->getName (),
73- 'type ' => 'to '
66+ $ recipients = ['to ' => $ message ->getTo (), 'cc ' => $ message ->getCc (), 'bcc ' => $ message ->getBcc ()];
67+
68+ $ to = [];
69+ foreach ($ recipients as $ type => $ emails ) {
70+ if (empty ($ emails )) continue ;
71+ foreach ($ emails as $ email ) {
72+ $ to [] = [
73+ 'email ' => $ email ->getEmail (),
74+ 'name ' => $ email ->getName (),
75+ 'type ' => $ type
7476 ];
7577 }
76-
77- if ($ cc = $ message ->getCc ()) {
78- foreach ($ cc as $ address ) {
79- $ toArray [] = [
80- 'email ' => $ address ->getEmail (),
81- 'name ' => $ address ->getName (),
82- 'type ' => 'cc '
83- ];
84- }
85- }
86-
87- if ($ bcc = $ message ->getBcc ()) {
88- foreach ($ bcc as $ address ) {
89- $ toArray [] = [
90- 'email ' => $ address ->getEmail (),
91- 'name ' => $ address ->getName (),
92- 'type ' => 'bcc '
93- ];
94- }
95- }
96-
97- $ mandrillMessage ['to ' ] = $ toArray ;
9878 }
9979
80+ $ mandrillMessage ['to ' ] = $ to ;
81+
10082 // Attachments.
10183 if (0 < $ message ->getAttachmentsSize () && $ message ->getAttachmentsSize () < $ this ->attachmentsSizeLimit
10284 && $ attachments = $ message ->getAttachments ()
@@ -113,10 +95,7 @@ public function send(MailMessage $message)
11395 $ mandrillMessage ['attachments ' ] = $ attachmentsArray ;
11496 }
11597
116- $ async = false ;
117- $ ip_pool = 'Main Pool ' ;
118- $ send_at = date ('Y-m-d h:i:s ' );
119- $ result = $ mandrill ->messages ->send ($ mandrillMessage , $ async , $ ip_pool , $ send_at );
98+ $ result = $ mandrill ->messages ->send ($ mandrillMessage );
12099
121100 return $ result ;
122101 } catch (Mandrill_Error $ e ) {
@@ -134,4 +113,4 @@ public function getErrors()
134113 {
135114 return $ this ->errors ;
136115 }
137- }
116+ }
0 commit comments