function Messaging_HTML_MailSystem::mimemail_multipart_body in Messaging 7
Parameters
$parts: an array of parts to be included each part is itself an array: array( 'name' => $name the name of the attachement 'content' => $content textual content 'file' => $file a file 'Content-Type' => Content type of either file or content. Mandatory for content, optional for file. If not present, it will be derived from file the file if mime_content_type is available. If not, application/octet-stream is used. 'Content-Disposition' => optional, inline is assumed 'Content-Transfer-Encoding' => optional, base64 is assumed for files 8bit for other content. 'Content-ID' => optional, for in-mail references to attachements. ) name is mandatory, one of content and file is required, they are mutually exclusive.
$content_type: Content-Type for the combined message, optional, default: multipart/mixed
Return value
an array containing the elements 'header' and 'body'. 'body' is the mime encoded multipart body of a mail. 'headers' is an array that includes some headers for the mail to be sent.
1 call to Messaging_HTML_MailSystem::mimemail_multipart_body()
- Messaging_HTML_MailSystem::mimemail_html_body in messaging_htmlmail/
messaging_htmlmail.inc - Generate a multipart message body with a text alternative for some html text
File
- messaging_htmlmail/
messaging_htmlmail.inc, line 275 - Drupal Messaging Framework - Send_Method class file
Class
- Messaging_HTML_MailSystem
- Sendgrid mail system
Code
function mimemail_multipart_body($parts, $content_type = 'multipart/mixed; charset=utf-8', $sub_part = FALSE) {
$boundary = md5(uniqid(time()));
$body = '';
$headers = array(
'Content-Type' => "{$content_type}; boundary=\"{$boundary}\"",
);
if (!$sub_part) {
$headers['MIME-Version'] = '1.0';
$body = "This is a multi-part message in MIME format.\n";
}
foreach ($parts as $part) {
$part_headers = array();
if (isset($part['Content-ID'])) {
$part_headers['Content-ID'] = '<' . $part['Content-ID'] . '>';
}
if (isset($part['Content-Type'])) {
$part_headers['Content-Type'] = $part['Content-Type'];
}
if (isset($part['Content-Disposition'])) {
$part_headers['Content-Disposition'] = $part['Content-Disposition'];
}
else {
$part_headers['Content-Disposition'] = 'inline';
}
if (isset($part['Content-Transfer-Encoding'])) {
$part_headers['Content-Transfer-Encoding'] = $part['Content-Transfer-Encoding'];
}
// mail content provided as a string
if (isset($part['content']) && $part['content']) {
if (!isset($part['Content-Transfer-Encoding'])) {
$part_headers['Content-Transfer-Encoding'] = '8bit';
}
$part_body = $part['content'];
if (isset($part['name'])) {
$part_headers['Content-Type'] .= '; name="' . $part['name'] . '"';
$part_headers['Content-Disposition'] .= '; filename="' . $part['name'] . '"';
}
// mail content references in a filename
}
else {
if (!isset($part['Content-Transfer-Encoding'])) {
$part_headers['Content-Transfer-Encoding'] = 'base64';
}
if (!isset($part['Content-Type'])) {
$part['Content-Type'] = file_get_mimetype($part['file']);
}
if (isset($part['name'])) {
$part_headers['Content-Type'] .= '; name="' . $part['name'] . '"';
$part_headers['Content-Disposition'] .= '; filename="' . $part['name'] . '"';
}
if (isset($part['file'])) {
$part_body = chunk_split(base64_encode(file_get_contents($part['file'])));
}
}
$body .= "\n--{$boundary}\n";
$body .= $this
->mimemail_rfc_headers($part_headers) . "\n\n";
$body .= $part_body;
}
$body .= "\n--{$boundary}--\n";
return array(
'headers' => $headers,
'body' => $body,
);
}