Background:
I'm working on a site that has frontend registration with some custom fields. The client would like to have a notification email whenever someone activates their account, containing the info on that user (so name, email and the custom fields).
Issue at hand:
For some reason, I'm getting the following error when I try to send an HTML email on the 'onActivateUser':
Unable to find the template “_emails/customer-service-notification”.
If however I try to send a plain text email, it all goes without problem.
I'd prefer to send out an HTML email so I'd like to resolve this.
What I already tried:
- Triggering the service function in another way (via custom controller action) sends the html email just fine
- Sending the mail by just setting the content as string in the function works just fine
Code:
Main plugin file - init function
craft()->on('users.onActivateUser', function (Event $event){
$user = $event->params['user'];
craft()->plugin_customerServiceNotification->sendNotificationMail($user);
});
customerServiceNotification
public function sendNotificationMail(UserModel $user){
$mailer = craft()->email;
$mailToBeSent = new EmailModel();
$mailToBeSent->subject = Craft::t('Nieuwe gebruiker geregistreerd');
$mailToBeSent->fromName = 'xyz';
$mailToBeSent->sender = '[email protected]';
$mailToBeSent->toEmail = '[email protected]';
$content = craft()->templates->render(
'_emails/customer-service-notification',
[
'userInfo' => [
'email' => $user->email,
'name' => $user->fullName,
],
]
);
$mailToBeSent->htmlBody = $content;
$mailer->sendEmail($mailToBeSent);
}
Folder structure:
craft()->templates->setTemplateMode(TemplateMode::Site);
line before the call tocraft()->templates->render()
.