1

I could've sworn I've read somewhere on here that the contact form plugin should use the same template as defined in the site's email settings, but it's not working for me.

Does anyone know if the Contact Form plugin supports this (and has it working)?

1

The first part of the answer in the post you linked to is wrong in the context of the Contact Form plugin.

Craft only takes the custom "HTML Template Path" email setting into account when EmailService's sendEmailByKey is called, which is used for pre-defined Craft emails.

The Contact Form uses EmailService's sendEmail, which won't take it into account.

It hasn't been released as part of an official Contact Form plugin release yet so there's no documentation, but thanks to this pull request, you've got an onBeforeMessageCompile event that will give a plugin a chance to modify the contents of the email.

|improve this answer|||||
  • Thanks for clearing up the confusion. Easiest thing was just adding the template HTML to the email body within ContactFormService.php. – Clive Portman Jul 28 '16 at 12:51
1

As Brad points out in his answer, the Contact Form plugin doesn't use the same template. I found the easiest thing to do was replace:

$email->body      = $message->message;

with:

$htmlTemplateTopHalf= <<<TEMPLATETOP
    // insert html here
TEMPLATETOP;

$htmlTemplateBottomHalf= <<<TEMPLATEBOTTOM
    // insert html here
TEMPLATEBOTTOM;

$email->body      = $htmlTemplateTopHalf;
$email->body      .= $message->message;
$email->body      .= $htmlTemplateBottomHalf;
|improve this answer|||||
1

For anyone interested, you can use Contact Form Templates to make custom email templates in Craft CMS 3.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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