add attachment to email if it exists
This commit is contained in:
@@ -303,7 +303,7 @@ function _booking_partialbalance_payment_email($nid) {
|
||||
* @param $email_type - select which custom email template to use
|
||||
* @return nothing
|
||||
*/
|
||||
function _booking_custom_email($nid, $email_type, $sender = 'contact') {
|
||||
function _booking_custom_email($nid, $email_type, $sender = 'contact', $attachment = NULL) {
|
||||
global $event;
|
||||
global $user;
|
||||
$language = user_preferred_language($user);
|
||||
@@ -326,14 +326,7 @@ function _booking_custom_email($nid, $email_type, $sender = 'contact') {
|
||||
//calculate the from email address for a logistics email
|
||||
$from = t('!event Registrations <!email>', 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['attachment'] = $attachment;
|
||||
));
|
||||
}
|
||||
|
||||
//load the node matching this id
|
||||
@@ -356,7 +349,17 @@ function _booking_custom_email($nid, $email_type, $sender = 'contact') {
|
||||
$message_body = isset($message_body['format']) ? $message_body['value'] : $message_body;
|
||||
$message_body = token_replace($message_body, $tokens);
|
||||
$themed_body = _booking_generate_html_body($subject, $message_body, $tokens);
|
||||
$params['body'] = $themed_body;
|
||||
$params['body'] = $themed_body;
|
||||
|
||||
// If there was an attachment, then add it
|
||||
if ($attachment) {
|
||||
$file_uri = drupal_realpath($attachment->uri);
|
||||
// Make sure we can still access the file
|
||||
if (file_exists($file_uri) && fopen($file_uri, 'r') !== false) {
|
||||
watchdog('booking_debug', "Adding attachment !name to custom email.", array('!name' => $attachment->filename));
|
||||
$params['attachment'] = file_load($attachment->fid);
|
||||
}
|
||||
}
|
||||
|
||||
//send the email to the person
|
||||
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
|
||||
|
Reference in New Issue
Block a user