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

3 Answers 3

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.

1
  • Thanks for clearing up the confusion. Easiest thing was just adding the template HTML to the email body within ContactFormService.php. Commented Jul 28, 2016 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;
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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