From 0e35a832c11d03ecb286cc1c36bb8e4e0165d2de Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Sat, 16 Jun 2018 17:47:49 +1000 Subject: [PATCH] test email attachments --- booking.emails.inc | 9 ++++++++- booking.emails_admin.inc | 11 ++++------- booking.module | 6 ++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/booking.emails.inc b/booking.emails.inc index 5a015cc..c5fd520 100644 --- a/booking.emails.inc +++ b/booking.emails.inc @@ -325,7 +325,14 @@ function _booking_custom_email($nid, $email_type, $sender = 'contact') { //calculate the from email address for a logistics email $from = t('!event Registrations ', array('!event' => $event->booking_eventname, '!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from'))) - )); + )); + // Test email attachments with dummy file + $attachment = array( + 'filecontent' => file_get_contents(DRUPAL_ROOT . '/README.txt'), + 'filename' => 'test.txt', + 'filemime' => 'text/plain', + ); + $params['attachments'][] = $attachment; } //load the node matching this id diff --git a/booking.emails_admin.inc b/booking.emails_admin.inc index ebe8b20..bc6f0b2 100644 --- a/booking.emails_admin.inc +++ b/booking.emails_admin.inc @@ -593,13 +593,11 @@ function booking_manual_email_form($form, &$form_state) ); //add in the custom email types - for ($i = 1; $i <= variable_get('booking_custom_email_count','5'); $i++) - { + for ($i = 1; $i <= variable_get('booking_custom_email_count','5'); $i++) { $email_options_array['custom' . $i] = variable_get('booking_email_subject_custom' . $i, $event->booking_eventname . ' custom ' . $i); } //add in the custom email types from logistics - for ($i = 1; $i <= 5; $i++) - { + for ($i = 1; $i <= 5; $i++) { $email_options_array['customlogistics' . $i] = variable_get('booking_email_subject_customlogistics' . $i, $event->booking_eventname . ' logistics custom ' . $i) . " **Logistics**"; } @@ -664,14 +662,13 @@ function booking_manual_email_form($form, &$form_state) '#value' => t('Send Email'), ); - if (variable_get('booking_enable_travelform', 0) == 1) { + if (variable_get('booking_enable_travelform', 0) == 1) { $header['travel_form'] = array('data' => t('Travel Submitted?'), 'field' => 'tid'); } //query the database for studygroup info if it is enabled - if (variable_get('booking_enable_studygroups', 0) == 1) - { + if (variable_get('booking_enable_studygroups', 0) == 1) { //select entries from the study groups mapping table $query = db_select('booking_studygroup_mapping', 'm'); $query->join('booking_studygroup_list', 's', 's.sid = m.booking_studygroup_id'); diff --git a/booking.module b/booking.module index f2970b9..e5d0569 100644 --- a/booking.module +++ b/booking.module @@ -974,6 +974,12 @@ function booking_mail($key, &$message, $params) { $message['headers'] += $params['headers']; } + // Add attachment when available. + // From https://drupal.stackexchange.com/questions/101035/send-attachments-with-drupal-mail + if (isset($params['attachment'])) { + $message['params']['attachments'][] = $params['attachment']; + } + //watchdog('booking_debug', "
Mail hook:\n@info
", array('@info' => print_r( $message, true))); }