1

There are some email templates on the admin interface of the user account settings.

I want to load that email template and change the token value dynamically in my custom module and then send that email?

Any one who have some idea?

1

I have found the solution. Below is the method I followed.

I added the new email template to the user account settings form using the following code.

$form['custom_email_template'] = array(
    '#type' => 'fieldset',
    '#title' => t('Contributor Email on Miles recieved'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
    '#group' => 'email',
  );
  $form['custom_email_template']['user_mail_custom_email_template_subject'] = Array(
    '#type' => 'textfield',
    '#title' => 'Subject',
    '#default_value' => variable_get('user_mail_custom_email_template_subject'),
    '#maxlength' => 180,
  );
  $form['custom_email_template']['user_mail_custom_email_template_body'] = Array(
    '#type' => 'textarea',
    '#title' => 'Body',
    '#default_value' => variable_get('user_mail_custom_email_template_body'),
    '#rows' => 15,
  );

And then on the 2nd submit handler of the user account settings form I used the following code to save the email content in a drupal variable.

variable_set('user_mail_custom_email_template_subject', $form_state['values']['custom_email_template']['user_mail_custom_email_template_subject']);
variable_set('user_mail_custom_email_template_body', $form_state['values']['custom_email_template']['user_mail_custom_email_template_body']);

and then use the following code to get the content of the email template.

$body = variable_get('user_mail_custom_email_template_body');
$subject = variable_get('user_mail_custom_email_template_subject');

and used the str_replace() function to replace the tokens with the dynamic values.

Hope it will help someone.

0

Use the Mime Mail module. It contains a mime-message.tpl.php which we should copy to our theme's template folder. Modify it as per your requirement.

We cannot send HTML tags using SMTP mail type.

  • I am talking about email templates not about theme's template file for the email. – Ahmad Aug 25 '14 at 11:31

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.