I am trying to complete sending mail with attachments
Problem: Email is sending without message body and attachments
Goal: send utf-8
html
email with attachments
I created so far ...
Usage:
email_library.php
<?php
private function create_body()
{
$this->body[] = "--{$this->uid}";
$this->body[] = "Content-type: text/html; charset=utf-8";
$this->body[] = "Content-Transfer-Encoding: 7bit";
$this->body[] = $this->message;
if (!empty($this->attachments)) {
foreach ($this->attachments as $k => $a) {
$this->body[] = "--{$this->uid}";
$this->body[] = "Content-Type: application/octet-stream; name=\"{$a['name']}\"";
$this->body[] = "Content-Description: {$a['name']}";
$this->body[] = "Content-Transfer-Encoding: base64";
$this->body[] = "Content-Disposition: attachment; filename=\"{$a['name']}\"";
$this->body[] = "{$a['data']}";
}
}
$this->body[] = "--{$this->uid}--";
}
EDIT:
$this->body[] = "--{$this->uid}";
removing "--"
The encapsulation boundary following the last body part is a distinguished delimiter that indicates that no further body parts will follow.
When working with a multipart message, you need to separate each part (message body + attachments) with two line breaks before the
--==MIME_BOUNDARY
! Otherwise they do not separate properly in your message.Simply add
\n
to your existing code:Disclaimer: I have not tested any of this, hopefully it works.
For more information, check out RFC 1521