@@ -80,9 +80,10 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
80
80
81
81
];
82
82
83
+
83
84
$ attachments = $ message ->getChildren ();
84
- $ count = count ($ attachments );
85
- if (is_array ( $ attachments ) && $ count > 0 ) {
85
+ $ attachmentCount = $ this -> checkAttachmentCount ($ attachments );
86
+ if ($ attachmentCount > 0 ) {
86
87
$ data = $ this ->attach ($ attachments , $ data );
87
88
}
88
89
$ ch = curl_init ();
@@ -99,8 +100,8 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
99
100
$ result = curl_exec ($ ch );
100
101
curl_close ($ ch );
101
102
102
- if ($ count > 0 ) {
103
- $ this ->deleteTempAttachmentFiles ($ data , $ count );
103
+ if ($ attachmentCount > 0 ) {
104
+ $ this ->deleteTempAttachmentFiles ($ data , $ attachmentCount );
104
105
}
105
106
106
107
return $ result ;
@@ -118,22 +119,41 @@ public function attach($attachments, $data)
118
119
if (is_array ($ attachments ) && count ($ attachments ) > 0 ) {
119
120
$ i = 1 ;
120
121
foreach ($ attachments AS $ attachment ) {
121
- $ attachedFile = $ attachment ->getBody ();
122
- $ fileName = $ attachment ->getFilename ();
123
- $ ext = pathinfo ($ fileName , PATHINFO_EXTENSION );
124
- $ tempName = uniqid () . '. ' . $ ext ;
125
- Storage::put ($ tempName , $ attachedFile );
126
- $ type = $ attachment ->getContentType ();
127
- $ attachedFilePath = storage_path ('app \\' . $ tempName );
128
- $ data ['file_ ' . $ i ] = new \CurlFile ($ attachedFilePath , $ type , $ fileName );
129
- $ i ++;
122
+ if ($ attachment instanceof \Swift_Attachment) {
123
+ $ attachedFile = $ attachment ->getBody ();
124
+ $ fileName = $ attachment ->getFilename ();
125
+ $ ext = pathinfo ($ fileName , PATHINFO_EXTENSION );
126
+ $ tempName = uniqid () . '. ' . $ ext ;
127
+ Storage::put ($ tempName , $ attachedFile );
128
+ $ type = $ attachment ->getContentType ();
129
+ $ attachedFilePath = storage_path ('app \\' . $ tempName );
130
+ $ data ['file_ ' . $ i ] = new \CurlFile ($ attachedFilePath , $ type , $ fileName );
131
+ $ i ++;
132
+ }
130
133
}
131
134
}
132
135
133
136
return $ data ;
134
137
}
135
138
136
139
140
+ /**
141
+ * Check Swift_Attachment count
142
+ * @param $attachments
143
+ * @return bool
144
+ */
145
+ public function checkAttachmentCount ($ attachments )
146
+ {
147
+ $ count = 0 ;
148
+ foreach ($ attachments AS $ attachment ) {
149
+ if ($ attachment instanceof \Swift_Attachment) {
150
+ $ count ++;
151
+ }
152
+ }
153
+ return $ count ;
154
+ }
155
+
156
+
137
157
/**
138
158
* Get the plain text part.
139
159
*
0 commit comments