Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joomla email template #1064

Open
micker opened this issue Jun 8, 2022 · 2 comments
Open

Joomla email template #1064

micker opened this issue Jun 8, 2022 · 2 comments

Comments

@micker
Copy link
Member

micker commented Jun 8, 2022

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

image

@micker
Copy link
Member Author

micker commented Jan 11, 2023

a commit about this
joomla/joomla-cms#37860

@micker
Copy link
Member Author

micker commented Oct 11, 2023

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($template_id, $tags)
    {
    $result = MailTemplate::createTemplate(
    'com_'.$this->compName.'.'.$template_id,
    '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);

} /**

  • Send out an email using the template layout

  • @param string $template_id mandatory (full template_id ie com_mycomponent.tripnew)

  • @param object $item mandatory - containing all relevant info

  • @param string $link optional

  • @param string $filename optional - name of the file if required without full path

  • @param string $attachment optional - including full path

  • @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['link_text'] = 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

  • Add email template selector in category option
  • Add system to add new template (an sql request to add new template)
  • Checl field remplacement (maybe only compatible with flexi_pro ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants