Open micker opened 2 years ago
some reference `In my install script I have:
8:45 AM use \Joomla\CMS\Mail\MailTemplate;
8:45 AM /**
Create a new Mail Template */ public function addMailTemplate($templateid, $tags) { $result = MailTemplate::createTemplate( 'com'.$this->compName.'.'.$templateid, 'COM'.STRTOUPPER($this->compName).'EMAILTMPL'.STRTOUPPER($template_id).'SUBJECT', 'COM'.STRTOUPPER($this->compName).'EMAILTMPL'.STRTOUPPER($template_id).'BODY', $tags, 'COM'.STRTOUPPER($this->compName).'EMAILTMPL'.STRTOUPPER($template_id).'_HTMLBODY' );
Factory::getApplication()->enqueueMessage('Email Template Record Created . . . '.$template_id);
}
/**
@return boolean false on fail */ public static function sendEmailTmpl($template_id, $item, $link = null, $filename = null, $attachfile = null) { $params = ComponentHelper::getParams('com_mycomponent'); $app = Factory::getApplication(); $mailfrom = $app->get('mailfrom'); $tmplId = explode('.', $template_id)[1];
// load all the data elements as set in the template setup $data = array(); $data['sitename'] = $app->get('sitename'); if ($link) { $mode = $app->get('force_ssl', 0) == 2 ? 1 : (-1); $data['linktext'] = Route::($link, false, $mode); } $data['coord_name'] = (isset($item->coord_name) && $item->coord_name > '') ? $item->coord_name : ''; $data['trip_title'] = $item->trip_details->title; $data['dept_date'] = $item->dept_date_disp; $data['leader_name'] = $item->leader_name; $data['booking_status'] = (isset($item->booking_status) && $item->booking_status > '') ? $item->booking_status : '';
foreach ($item->members as $recip) { if (isset($item->att_name) && $item->att_name > '') { $data['member_name'] = $item->att_name; $name = isset($recip->full_name) ? $recip->full_name : $recip->name; } else { $name = isset($recip->full_name) ? $recip->full_name : $recip->name; $data['member_name'] = $name; }
// Build the email and send
$mailer = new MailTemplate($template_id, $app->getLanguage()->getTag());
$mailer->addTemplateData($data);
$mailer->setReplyTo($mailfrom, $data['sitename']);
$mailer->addRecipient($recip->email, $name);
if ($attachfile) {
$mailer->addAttachment($filename, $attachfile);
}
// Try to send the email.
try {
$return = $mailer->send();
} catch (\Exception $exception) {
$app->enqueueMessage(Text::_($exception->getMessage()), 'warning');
$return = false;
}
}
if ($return) { $app->enqueueMessage(Text::_('COM_MYCOMPONENT_MAIL_SEND_SUCCESSFUL'), 'success'); }
return $return; }` Maybe we can do
it will be cool to use and add flexicontent to joomla email templating (j4) it will be more flexible and powerfull (we can have for free and more tag remplacement for flexipro plugin) => akeeba engage have done it !![image](https://user-images.githubusercontent.com/2539440/172697460-b34cb4ff-d1a5-453b-9223-2fb5ec42736d.png)