Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Message Template" setting #72

Open
brandonkelly opened this issue Mar 14, 2017 · 12 comments
Open

"Message Template" setting #72

brandonkelly opened this issue Mar 14, 2017 · 12 comments

Comments

@brandonkelly
Copy link
Member

This could be used to customize the body contents, such as include the sender's email address within the message body.

@outline4
Copy link

outline4 commented Jun 3, 2017

+1

@brandonkelly
Copy link
Member Author

Hah, I don't even remember posting this FR, but worth mentioning that a plugin can take over the message rendering using the beforeMessageCompile event (v1) or beforeSend event (v2).

@outline4
Copy link

outline4 commented Jun 4, 2017

I know that... But it seems to be hard to achieve and kind of buggy.

I mean, the advantage over other add-ons it's that it's free and easy... If I'd had to customize it, there's no point in using this add-on.

Hiding the reply email and name within the "reply to" field is just not so very natural...
Having the name and email address within the body is much more failsafe, logic and it's easy to implement... Even for me :)

It's just adding:

$email->htmlBody = '<p>Name: '.$message->fromName.'</p>';
$email->htmlBody .= '<p>Email Adresse: '.$message->fromEmail.'</p>';

before

// Prevent Twig tags from getting parsed
// add the "." before "=" when customizing this
$email->htmlBody .= str_replace(array('{', '}'), array('&lbrace;', '&rbrace;'), $message->htmlMessage);

+💯

@benblub
Copy link

benblub commented Dec 21, 2017

@outline4 thanks

@KevinBeckers
Copy link

$email->htmlBody = '<p>Name: '.$message->fromName.'</p>';
$email->htmlBody .= '<p>Email Adresse: '.$message->fromEmail.'</p>';

@outline4 Where did you add these lines??

@piotrpog
Copy link

piotrpog commented Apr 4, 2019

Please include such functionality. Honestly, its pretty much basic thing to have in any contact form plugin.

@bertoost
Copy link

A template would be nice. A little enchantment for now;
#161

@LukePeters
Copy link

@KevinBeckers I just wrote a simple Craft CMS module to solve this problem, if it's of interest. It can probably be done in a far more elegant way, but this works for my use case. https://github.com/LukePeters/contactformextras

@Friksel
Copy link

Friksel commented Apr 15, 2020

+1
A way to set a template for the email body is a pretty basic requirement and the body now is pretty primitive. I'm surprised it's not possible with this plugin with Craft having a full Twig template system on board.

@billmn
Copy link
Contributor

billmn commented Sep 14, 2020

Yes please, the ability to set a template would be very useful!

@kevinmu17
Copy link

@brandonkelly

Hah, I don't even remember posting this FR, but worth mentioning that a plugin can take over the message rendering using the beforeMessageCompile event (v1) or beforeSend event (v2).

I'm trying to do this with the beforesend event but this doesn't seem to do anything at all. When following the code of contact-form v2, the message is already compiled before this event is fired. Also, there is a foreach on line 119 in Mailer.php which is not using the $event->message. So am i correct when saying this is impossible to achieve?

@kevinmu17
Copy link

kevinmu17 commented Jul 22, 2021

N.V.M. i made a stupid assumption/mistake.

Here is the code for people who want to achieve the same.

Event::on(Mailer::class, Mailer::EVENT_BEFORE_SEND, function(SendEvent $e) {
        // Change whatever you want in your submission data ($e->submission->message)
        $e->message->setTextBody($text);
        $e->message->setHtmlBody($html);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants