test email attachments

This commit is contained in:
Nathan Coad
2018-06-16 17:47:49 +10:00
parent 855c114b2b
commit 0e35a832c1
3 changed files with 18 additions and 8 deletions

View File

@@ -325,7 +325,14 @@ function _booking_custom_email($nid, $email_type, $sender = 'contact') {
//calculate the from email address for a logistics email //calculate the from email address for a logistics email
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname, $from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from'))) '!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 //load the node matching this id

View File

@@ -593,13 +593,11 @@ function booking_manual_email_form($form, &$form_state)
); );
//add in the custom email types //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); $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 //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, $email_options_array['customlogistics' . $i] = variable_get('booking_email_subject_customlogistics' . $i,
$event->booking_eventname . ' logistics custom ' . $i) . " **Logistics**"; $event->booking_eventname . ' logistics custom ' . $i) . " **Logistics**";
} }
@@ -664,14 +662,13 @@ function booking_manual_email_form($form, &$form_state)
'#value' => t('Send Email'), '#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'); $header['travel_form'] = array('data' => t('Travel Submitted?'), 'field' => 'tid');
} }
//query the database for studygroup info if it is enabled //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 //select entries from the study groups mapping table
$query = db_select('booking_studygroup_mapping', 'm'); $query = db_select('booking_studygroup_mapping', 'm');
$query->join('booking_studygroup_list', 's', 's.sid = m.booking_studygroup_id'); $query->join('booking_studygroup_list', 's', 's.sid = m.booking_studygroup_id');

View File

@@ -974,6 +974,12 @@ function booking_mail($key, &$message, $params) {
$message['headers'] += $params['headers']; $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', "<pre>Mail hook:\n@info</pre>", array('@info' => print_r( $message, true))); //watchdog('booking_debug', "<pre>Mail hook:\n@info</pre>", array('@info' => print_r( $message, true)));
} }