Skip to content
A quick and dirty class for sending emails with attachments in PHP
Find file
Pull request Compare This branch is 3 commits behind ngmaloney:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


AttachmentEmail is a simple php class used for sending emails with attachments.
It is a modified version of a script found at
( While it is
platform agnostic,  it was developed to get around the complexities of sending
an email with attachments in Drupal 7. The primary modules for doing so haven't
yet been ported from D6.


PHP Example


//The following code is for example only.


$subject="Check out this report!";
$message="Yo! Check out this report!";
$attachment = array(
  'url' => '~/documents/report.pdf',
  'filename' => 'report.pdf',

$email = new AttachmentEmail($to, $from, $subject, $message, $attachment);


Drupal 7 Example (partial)

mymodule_form($form, &$form_state) {
  $form['to'] = array(
    '#type' => 'textfield',
    '#title' => t('To'),
  $form['from'] = array(
    '#type' => 'textfield',
    '#title' => t('From'),
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
  $form['file'] = array(
    '#type' => 'file',
    '#title' => t('Attachment'),
  $form['send'] = array(
    '#type' => 'submit',
    '#value' => t('Send'),

mymodule_form_submit($form, &$form_state) {
  //Include Attachment Emailer
  module_load_include('php','mymodule', 'attachment_email');

  $to = $form_state['values']['to'];
  $from = $form_state['values']['from'];
  $message = $form_state['values']['message'];
  $attachment = file_save_upload('attachment');

  //Send Email!
  $email = new AttachmentEmail($to, $from, $message, $body);

  //perform any addition logic....


Something went wrong with that request. Please try again.