You are here

function _contact_attach_add_attachment in Contact Attach 5

Same name and namespace in other branches
  1. 6 contact_attach.module \_contact_attach_add_attachment()
  2. 7 contact_attach.module \_contact_attach_add_attachment()

Add an attachment to the message body.

Parameters

file: An attachment to add to the message.

Return value

The processed attachment, ready for appending to the message.

1 call to _contact_attach_add_attachment()
_contact_attach_process_attachments in ./contact_attach.module
Check for attachments and process them, if one or more exists.

File

./contact_attach.module, line 498
This is the main code file for the Contact attach module. This module gives users the ability of attaching one or more files to e-mails sent using the site-wide contact form.

Code

function _contact_attach_add_attachment($file) {
  $attachment = "Content-Type: " . $file->filemime . "; name=\"" . basename($file->filename) . "\"\n";
  $attachment .= "Content-Transfer-Encoding: base64\n";
  $attachment .= "Content-Disposition: attachment; filename=\"" . basename($file->filename) . "\"\n\n";
  if (file_exists($file->filepath)) {
    $attachment .= chunk_split(base64_encode(file_get_contents($file->filepath)));
  }
  else {
    $attachment .= chunk_split(base64_encode(file_get_contents(file_directory_temp() . '/' . $file->filename)));
  }
  return $attachment;
}