0

After about two days trying to use Mailpoets E-Mail-Templates to send notifications from my own code (own plugin) I'm getting a little desperate...

What I want is the possibility for a user to edit certain E-Mail-Templates which will be send for a variety of events on the website. Yes, this would be transactional E-Mails but they won't fit the default Wordpress ones nor the triggers available in Mailpoet.

I actually managed to kind of abuse Mailpoets "send on list subscription" but in doing so I would need to set the recipients to "subscribed" which in turn would clash with the reason Mailpoet is installed on the site in the first place: We need Double-Opt-In for Newsletters, but messing around with the confirmation status would break that flow.

So I'm looking for

  • a way to send Mailpoet E-Mail-Template without an actual subscriber (which according to an old question on their forum isn't possible)

OR

  • another plugin to design a variety of different E-Mail which could be queried from PHP and used in whatever way.

Basically: I want to send E-Mails from my plugin, but am way to lazy to hardcode templates (aside from the inflexibility) or to code a UI for generating Templates myself.

0

For now I have what I want. I can get the E-Mail Template by (ab)using the DI which Mailpoet uses and then send with whatever I want.

So for documentation:

$nl_repo = MailPoet\DI\ContainerWrapper::getInstance()
    ->get(\MailPoet\Newsletter\NewslettersRepository::class);
$renderer = MailPoet\DI\ContainerWrapper::getInstance()
    ->get(\MailPoet\Newsletter\Renderer\Renderer::class);

$rendering = $renderer->render($nl_repo->findOneById(8));
$mail_body = do_shortcode($rendering['html']);

$mail = wp_mail(
    'somemail@example.com',
    'Subject',
    $mail_body,
    array('Content-Type: text/html; charset=UTF-8')
);

Haven't figured out how to get the Mailpoet fields and just using my own shortcodes for now, but if I don't post it here now I would most probably forget later.

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