Back to MailTemplate class

Method createTemplate

public static bool
createTemplate
(mixed $key, mixed $subject, mixed $body, mixed $tags, mixed $htmlbody = '')
Insert a new mail template into the system
Parameters
  • string $key Mail template key
  • string $subject A default subject (normally a translatable string)
  • string $body A default body (normally a translatable string)
  • array $tags Associative array of tags to replace
  • string $htmlbody A default htmlbody (normally a translatable string)
Returns
  • bool True on success, false on failure
Since
  • 4.0.0
Class: MailTemplate
Project: Joomla

Method createTemplate - Source code

/**
 * Insert a new mail template into the system
 *
 * @param   string  $key       Mail template key
 * @param   string  $subject   A default subject (normally a translatable string)
 * @param   string  $body      A default body (normally a translatable string)
 * @param   array   $tags      Associative array of tags to replace
 * @param   string  $htmlbody  A default htmlbody (normally a translatable string)
 *
 * @return  boolean  True on success, false on failure
 *
 * @since   4.0.0
 */
public static function createTemplate($key, $subject, $body, $tags, $htmlbody = '')
{
    $db = Factory::getDbo();
    $template = new \stdClass();
    $template->template_id = $key;
    $template->language = '';
    $template->subject = $subject;
    $template->body = $body;
    $template->htmlbody = $htmlbody;
    $template->attachments = '';
    $params = new \stdClass();
    $params->tags = array($tags);
    $template->params = json_encode($params);
    return $db->insertObject('#__mail_templates', $template);
}