By gekomees on
How should I go about theming the contact form email sent?
I have looked into the Mailsystem and Mime Mail but fail to understand how either of those will help me style the email.
The default e-mail looks like this:
Link to Image
There is no way I can use this horror in an an actual production site. How this thing got through D8 beta is beyond me.
Basically what is making the email such is line 146 in contact.module in /core/modules/contact but I can't very well go and change core files, can I?
Comments
I want to look into this -
I want to look into this - can you confirm that you have added custom fields to the contact form? Have you done anything else (such as alter the manage display settings), I just need to know the details so I can reproduce the formatting.
Another thing that might be helpful - attach a text file with the raw source of the email.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
You mean this is not normal?
You mean this is not normal?
Well, here are my fields:
https://gyazo.com/1c2583c70df08647dfc19e96cf4da0bf
Not sure what qualifies as a custom field though.
I've probably also changed display settings:
https://gyazo.com/264f4b540bd33232b7d3cdbad602a4a4
I've definitely changed altered form display:
https://gyazo.com/2cceac1fb6d54055d277a62d9dd07478
I have some contact form enhancing modules also (you can see it in form display) but the email format was the same even before that.
Here's the source code. I've taken the liberty of erasing the URLs and IP addresses. If this is not what you meant, tell me what I need to post.
I really want to see the file
I really want to see the file, basically I want to know if the horizontal new lines are newline chars (probably be just blank lines), I'm not sure if the input format (used here in this forum comments) are converting those to paragraph tags.
No idea if this is "normal" or not, I'm just interested in learning how this all works in D8.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Well, it's just plaintext, so
Well, it's just plaintext, so there really are no paragraph tags.
I have exactly the same issue
I have exactly the same issue, here is the mail :
http://files.guillaumeboit.fr/mail.txt
Good to know, hopefully I'll
Good to know, hopefully I'll have some time to look at this later today, cheers.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Line breaks and formatting
I was just curious if anyone had come to any further conclusions on this issue. From everything that I've read, I get the impression that Drupal 8 is treating the contact form module as the answer to all front end, anonymous user forms, instead of the webforms module. My question would be, is this a correct impression?
If this is the case, what is the correct procedure for formatting the email message? Because with the way it is now, any form that has more than a couple extra fields really gets a very long email response. Below is what I pulled off of Gmail with just 3 extra test fields. I have a form that has 20+ fields and the client says they're getting 10 page emails as a response. And by the way, I tested this on a Hotmail account, and Hotmail ignored any HTML and simply returned one line. So 20+ fields would be a nightmare!
If this is NOT the way to handle front end webforms for anonymous users, what is the Drupal 8 way? Thanks for any suggestions!
I need to edit my email format as well.
My customer service gurus submitted a ticket for a format change. I would agree that it's not as neat and tidy as Drupal 7 options I'm used to working with or the account-related emails that offer an editing option in configuration settings. I'll dig deeper into this today. Let me know if you know of friendly ways to theme emails resulting from contact forms.
Worlds to explore. Worlds to create.
Blog: http://www.christopherstevens.cc/blog
Twitter: http://www.twitter.com/owntheweb
I'd be interested to hear if
I'd be interested to hear if you get any answers!
I'll post examples and links
I'll post examples and links once/if I get this figured out. I'm seeing lots of clues out there but require a Chipotle burrito first. :D
Worlds to explore. Worlds to create.
Blog: http://www.christopherstevens.cc/blog
Twitter: http://www.twitter.com/owntheweb
Update: This was moved to
Update: This was moved to Monday. It's hot on my radar.
Worlds to explore. Worlds to create.
Blog: http://www.christopherstevens.cc/blog
Twitter: http://www.twitter.com/owntheweb
No news, the client's ticket
No news, the client's ticket is still sleeping on my side. I believe they could cope... Now I'm back with D7 and it will be a looong time before I come back to D8 :)
...
As someone who has used both platforms for some years your comment is akin to being offered the choice between a Ferrari and an old van, and choosing the van because it was easier to change the tyre...
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Exactly my point!
Exactly my point!
Any news on this?
Is there somebody here that did find a solution on this.
My client is not happy with a email that is more than 1 mile long :-/
So really looking for a good solution.
What I currently do is use
What I currently do is use the YAML Form module. It has proper email handlers. Sadly it was not available when I first posted this topic.
Can YAML handle existing webforms created with the drupal Core?
Thanks Gekomees for your quick reply and solution!! Can you tell me if this module can work on the existing webforms? Because the website has already 4 long webforms... or will I have to recreate all those forms with the new module?
Most likely you'll have to
Most likely you'll have to recreate them. YAML form has been updated since I used it but I don't think form importing has been implemented.
Possible Solution - Contact Storage Export
Getting here a bit late, but just wanted to mention how I handled it.
Knowing that the goal was to collect the data and not really caring about the email, my solution was to use a module by the name of Contact Storage Export (which requires Contact Storage). Regardless of however poorly the email was formatted, this module allowed me to collect the data submitted in an exported .csv file. It ended up being exactly what my client was looking for.
So now, the email merely serves as a reminder to download a submitted form. Not a big deal when there's only 4 fields. Bigger deal when there were 70+. All in all, I know I'm perhaps stretching the intended use of the default forms, but for me it gets the job done. Hope this helps!
I used hook_mail_alter to get around this.
I ended up just assembling a custom body in a hook_mail_alter() in a helper module, which lets me control exactly what it looks like (as long as you're happy with a plain text email)
Yes, I think that is the best
Yes, I think that is the best simple solution. It seems very hard to theme an email template.
I improved this
I needed this to be more dynamic with custom added fields, so i improved it a bit if someone is interested:
I'm also experiencing this.
Just dropping a comment now so I can come back later with my findings, once I've discussed with colleagues here.
How do I assemble custom body in hook_mail_alter?
"I ended up just assembling a custom body in a hook_mail_alter() in a helper module" What does that mean exactly? I'm not very familiar with it. Do I need to create a custom file? Where do I place it?
Thanks!
File field is not accessible
Hello All,
I have added upload file field in contact form. I can fetch all other fields using,
$contact_message = $message['params']['contact_message'];
$fields = $contact_message->getFields();
foreach ($fields as $field_name => $field) {
$new_body .= $field->getFieldDefinition()->label()." ".
$contact_message->get($field_name)->getString() . PHP_EOL . PHP_EOL;
}
But for file field it giving me some number. Please help me out to show file URL in email.
Thanks.
with url to file
Thank you paultreny and heger245.
I've tweaked above code a bit to get links to uploaded files. Not sure if this is best approach but it works for my use case.
Thx ! Works fine with me. ;)
Thx ! Works fine with me. ;)
Manage Display Order
Hi, are your fields comming in the right order?
Because I need to do basically what you did, but the fields are all out of order based on the Manage Display Weight.
Kind regards,
André
Hi André,
Hi André,
with above code you will have Name, Email, then all the other fields. Haven't tried but I guess you could order fields with custom display for Token view mode.
Token
Sorry, I didn't understand the display for Token view mode, could you gave me an example?
"Custom display settings"
"Custom display settings" under Manage display.
Contrib Module
I also stumbled across this module Contact Emails which allows a lot of customization to the email body and subject via tokens, etc. Works great from the couple times I have used it.
John Ouellet
Sales Engineering Manager
https://thinktandem.io/
This module is what i needed
This module is what i needed to solve the problem stated in the top!
Thank you very much!