@@ -26,6 +26,8 @@ class MailjetEmailMessage
2626
2727 public array $ variables = [];
2828
29+ public array $ attachments = [];
30+
2931 public function templateId (int $ templateId ): static
3032 {
3133 $ this ->templateId = $ templateId ;
@@ -117,20 +119,43 @@ public function variable(string $key, $value): static
117119 return $ this ;
118120 }
119121
122+ public function attachments (array $ attachments ): static
123+ {
124+ $ this ->attachments = $ attachments ;
125+
126+ return $ this ;
127+ }
128+
129+ public function attachment (array $ attachment ): static
130+ {
131+ $ this ->attachments [] = $ attachment ;
132+
133+ return $ this ;
134+ }
135+
120136 public function toArray (): array
121137 {
138+ $ messagesData = [
139+ 'To ' => $ this ->to ,
140+ 'Cc ' => $ this ->cc ,
141+ 'Bcc ' => $ this ->bcc ,
142+ 'From ' => $ this ->from ,
143+ 'TemplateID ' => $ this ->templateId ,
144+ 'TemplateLanguage ' => $ this ->templateLanguage ,
145+ 'Subject ' => $ this ->subject ,
146+ ];
147+
148+ if (filled ($ this ->variables )) {
149+ $ messagesData ['Variables ' ] = $ this ->variables ;
150+ }
151+
152+ if (filled ($ this ->attachments )) {
153+ $ messagesData ['Attachments ' ] = $ this ->attachments ;
154+ }
155+
122156 return [
123157 'Messages ' => [
124- [
125- 'To ' => $ this ->to ,
126- 'Cc ' => $ this ->cc ,
127- 'Bcc ' => $ this ->bcc ,
128- 'From ' => $ this ->from ,
129- 'TemplateID ' => $ this ->templateId ,
130- 'TemplateLanguage ' => $ this ->templateLanguage ,
131- 'Subject ' => $ this ->subject ,
132- 'Variables ' => $ this ->variables ,
133- ],
158+ $ messagesData ,
134159 ],
135160 ];
136161 }
0 commit comments