How-To

Using tokens in email subject

ABPro 4.0.0

This article explains how to modify ABPro so it will support tokens in the subject of confirmation emails.

This should only be used for adding simple things like [resource] to the subject.
The ABPro token system supports almost any booking data to be included in a message. It should NOT be assumed all those tokens can be used in the subject of a message. Mail servers place different limits on an email subject than on the body.

Bottom line here: Use at your own risk.

There is a handy function in ABPro called processTokens.
This function takes a request_id (booking id) and some text. The return is the passed in text with any tokens replaced with values from the request or booking.

The catch here is that the confirmation subject is stored in one place (Configure screen, Basic Setup tab) but is used in many places. 
Unless the change outlined below is added everywhere, some messages will be sent with the token un-parsed.

 

I will present 2 variations here, one in which all messages get the token and another approach that allows only certain messages (admin but not customer for example) to get the token.

Variation 1 - For all messages you add the token to the message in the config screen and have all the emails call processTokens on the subject. 

Variation 2 - Leave config subject setting alone - no tokens, then modify the subject of the specific message type to include a token. Only available on front-end as backend uses a single call for all emails.

 

 

Line number specified are approximate and will vary slightly depending on which version of ABPro you are using.

 

Back-end just requires change to sendmail2.php.

File: \administrator\components\com_rsappt_pro3\sendmail_pro2.php

Around line 631 look for:

$mailer->addRecipient(explode(",", $to));
$mailer->setSubject($subject);
$mailer->setBody($message);

 Change to:

$mailer->addRecipient(explode(",", $to));
$mailer->setSubject(processTokens($request_id, $subject));

$mailer->setBody($message);

 

Front-end requires changes to controller for the booking screens.

The booking screen controller sends up to 3 emails (customer, admin, resource) so there will be 3 changes to be made.

File: \components\com_rsappt_pro3\controllers\process_booking_request.php

Around line 466, 491 and 516 look for:
$mailer->setSubject(JText::_($apptpro_config->mailSubject));

Change to:
$mailer->setSubject(JText::_(processTokens($last_id->last_id, $apptpro_config->mailSubject)));

 

 

Variation 2

In variation 2, you have not added any token to the subject in the ABPro Configure screen, instead you will add it just in the message you want (customer, admin or resource).

In the above files, rather than calling processTokens on the subject, you ADD to the subject.

Example:

To add [resource] to only the admin email, in line 419 you change:

$mailer->setSubject(JText::_($apptpro_config->mailSubject));

To this, adding the token "[resource]" and parsing it:

$mailer->setSubject(JText::_($apptpro_config->mailSubject)."-".processTokens($last_id->last_id,"[resource]"));