From a09dcd017bde5e997644b8e08a10edd6ea46e52f Mon Sep 17 00:00:00 2001 From: Tom Shaw Date: Mon, 1 Apr 2024 02:22:01 -0500 Subject: [PATCH] Attachment testing. --- src/Api/GoogleMail.php | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/Api/GoogleMail.php b/src/Api/GoogleMail.php index 93ab8d8..53bfb9e 100644 --- a/src/Api/GoogleMail.php +++ b/src/Api/GoogleMail.php @@ -357,34 +357,24 @@ protected function buildMessage(array $validated): string } $headers .= "Subject: {$validated['subject']}\r\n"; $headers .= "MIME-Version: 1.0\r\n"; + $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n\r\n"; - if (! empty($this->attachments)) { - $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n\r\n"; + foreach ($this->attachments as $attachment) { + $attachmentData = base64_encode(file_get_contents($attachment)); - // Add the text part $headers .= "--$boundary\r\n"; - $headers .= "Content-Type: text/html; charset=utf-8\r\n"; - $headers .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; - $headers .= "{$validated['message']}\r\n\r\n"; - - // Add each attachment - foreach ($this->attachments as $attachment) { - $attachmentData = base64_encode(file_get_contents($attachment)); - - $headers .= "--$boundary\r\n"; - $headers .= 'Content-Type: '.mime_content_type($attachment).'; name="'.basename($attachment)."\"\r\n"; - $headers .= "Content-Transfer-Encoding: base64\r\n\r\n"; - $headers .= $attachmentData."\r\n\r\n"; - } - - // End the email - $headers .= "--$boundary--"; - } else { - $headers .= "Content-Type: text/html; charset=utf-8\r\n"; - $headers .= 'Content-Transfer-Encoding: 8bit'."\r\n\r\n"; - $headers .= $validated['message']; + $headers .= 'Content-Type: '.mime_content_type($attachment).'; name="'.basename($attachment)."\"\r\n"; + $headers .= "Content-Transfer-Encoding: base64\r\n\r\n"; + $headers .= $attachmentData."\r\n\r\n"; } + $headers .= "--$boundary\r\n"; + $headers .= "Content-Type: text/html; charset=utf-8\r\n"; + $headers .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; + $headers .= "{$validated['message']}\r\n\r\n"; + + $headers .= "--$boundary--"; + return $headers; }