I don't know if this is the same kind of thing you are looking for, but I think it's close.
I created a plugin that handles a contact form submission. When the user fills out the form, an email is sent to me & the person who filled out the form. I'm not listening to onBeforeSendEmail
, but rather listening for a save
event that I call via controller.
I told Craft that I needed a settings area in my plugin, then I created a textarea where I could manage the email that was sent to the user(s). This is what that looks like:
<p>Hi {{firstName}} — thank you for reaching out to us!<br>We wanted to drop you a quick note that we've received your information and we'll be in touch very soon!</p><p>Regards,<br>The friendly folks at this website</p>
To get {{firstName}}
to use the value that were entered in the form, I used this in my plugin's service file.
That way it would read "Hi Steve - thank you for..."
MyPluginService.php
...
$email = new EmailModel();
$email->fromEmail = $emailSettings['emailAddress']; // set in CP
$email->replyTo = $emailSettings['emailAddress']; // set in CP
$email->sender = $emailSettings['emailAddress']; // set in CP
$email->fromName = $emailSettings['senderName']; // set in CP
$email->toEmail = $contact->email;
$email->subject = $settings->guestSubject;
$email->body = craft()->templates->renderString($settings->welcomeEmailMessage, array('firstName' => $contact->firstName));
if (craft()->email->sendEmail($email)) {
return true;
}
....
It's the craft()->templates->renderString()
part that lets me hook into my plugin to set the variable values.
Hope this helps!