Skip to content

Commit

Permalink
Attachment testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomshaw committed Apr 1, 2024
1 parent b608019 commit a09dcd0
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/Api/GoogleMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a09dcd0

Please sign in to comment.