0

I have to send some emails in a custom Drupal 7 module.

I'd like to use the PET module (Previewable email templates) to manage the templates and drupal_mail() to send emails because it already uses SwiftMailer to send emails. The problem is that the body of the email I get from Pet has some tokens that I should replace before the email is sent.

How can I replace them?

This is the code I'm using.

$pet = pet_load('test1');

$params['format']= "text/html";
$params['charset']= "UTF-8";
$params['email_subject']= $pet->subject;
$params['email_body']=$pet->mail_body;

///$params['email_body']= <body with token replaced>

drupal_mail('myLib', 'customNotifications', 'xxx@gmail.com', language_default(), $params);
0

I've solved in this way:

// SOSTITUZIONE TOKEN DRUPAL
$l_oPetTemplate = pet_load('test1');
$l_TemParams2['pet'] = $l_oPetTemplate;
$l_aSubstitutions = pet_substitutions($l_oPetTemplate, $l_TemParams2);
$l_aEmailParams['email_subject'] = token_replace($l_oPetTemplate->subject, $l_aSubstitutions, array('clear' => TRUE));
$l_aEmailParams['email_body']=token_replace($l_oPetTemplate->mail_body, $l_aSubstitutions, array('clear' => TRUE));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.