Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
I just want to add a single line of text after email notifications
piXelicidio
New
Hi,
I'm new here, and I'm liking Vanilla a lot.
I have being about 48 days sniffing the web and this forums looking for how to modify the email texts.
Non of the old discussions about this where clear enough or updated, leading me to dark unkown places in the PHP code (wich I dont understand) without any successful results.
Would be nice to be able to change the whole and all email templates, BUT i'm I'll happy just adding a line of text at the end of email notifications.
Can someone please help me?
Regards
0
Comments
Yeah...about that.
It used to be easy, but now email template are a bit of a mess TBH.
Personally my favoured method, is to override the template class (yes the actual class not a temperate itself), but that is not for everybody. Technically you can create your own and assign, if but if you do that, you can just as easily predefine the default.
The whole rush to provide a click button solution html email mean there is string concatenation harded coded rather then yielded variables. Thier button based html messages poorly translate to text based / or mixed content messages. They don't make much sense.
The previous method was all locale / definition based.
I'm not opposed to templates either it is just the implementation is unfortunate.
grep is your friend.
It's not easy, but it is absolutely possible.
But since it is not easy, you need to be more specific what your requirements are. Do you want to include a common text at the end of the mail or do you want to include something which is recipient specific?
Should that be at the end of every mail or only at the end of some new PN notifications or other specific event mails?
Are you using html mails or plain text mails?
Hi, thanks for replaying.
I just need to add a line of text with a link to unsubscribe or edit notifications. Thats my only main concern.
Start with the example plugin and add the following method:
You are leading me to my first plugin?! awesome and scary
Thanks
(creating backup...)
(20 minutes later)... I found the example plugin!
Trying to not touching anything on the example plugin and added your function after public function discussionsController_afterDiscussionTitle_handler($sender)
The example plugin functionality works but not the email modification. Tryied also switching to HTML emails and nothing. Maybe I have to do something else other than pasting the code there, but I donn't have any idea.
But I'm sure handler is called because I changed "getEmailTemplate()" for "emailTemplate()" and email notification stopped on the forum, until I set it back again to getEmailTemplate().
So maybe setMessage() is the one not working.
Finally I did it! SOLVED!
Was not of my wish to write PHP but you gave me the motivation to be brave.
I did a search on all vanilla files to find where the event beforeSendMail is triggered.
Found it on: class.email.php
After noticing "toString()" there I got attracted to try something and after studing your code I modifed this core funciton with:
And it successfully worked!
Thank you!
Maybe that's not good thing to do, modifying the core files, but I was very anxious to resolve this someway!
And I'm wondering why more people are not complaining about this, something so basic and essential as provide easly modifying the email templates.
@piXelicidio
don't modify the core, istead, the way to to do it. Is create an addon, and include a copy of this file. If it is already the auto load will not try to load the core file.
Also you are modifying the wrong file. Leave
class.email.php
alone. Instead copyclass.emailtemplate.php
and change that.e.g. if you make an and app you can put in the library folder. then include in in your apps settings/boostrap.php put
require_once PATH_APPLICATIONS.DS.'yourappname'.DS.'library'.DS.'class.emailtemplate.php';
changing
yourappname
to the name of the appgrep is your friend.
@piXelicidio No, you were so close!
Never ever change the core files. That will only lead to confusion on the next update and maybe even to severe problems if not done without exactly knowing what you are doing.
I hope you still have your example plugin? There is only one line missing:
By the way: you should delete every other method in that example plugin.
@x00 you can set a custom template by using the same event:
Ok... ok,, no core files modifications... (if... something else work )
@x00
Thanks for the help, but I can't follow, don't know how to do half of what you're telling me
@R_J
Added the line, and it works! but the extra line appears before "check it out"
There are many funcitons there, can I delete actually every other of them? Leaving gdn_email_beforeSendMail... isolated?
I will investigate on the "Check it out"
Your minimum and absolutely functionless plugin can look like this:
So yes, you can delete all other methods and only use the above.
The solution is
public function setFooter($text, $textColor = '', $backgroundColor = '')
Investigate (not change ) the class.emailtemplate.php and you might find other helpful ways to alter that mail
And what I forgot to add: that is what's making it easy to extend Vanilla!
If you prefer, you can turn off HTML mails again. They are not needed if you want to customize mails and your short plugin should work with plain text mails, too
There is line of text added to the end of the email, but it only says: "Array"
Tried to replace the printf with the previous way of concatenating strings and shows the same line: "Array"
Sending a literal string to setFooter also show the same thing "Array"
hey! it works, but only when switching to HTML emails...
Ok, good news, made it work with plain text too.
Using "if" condition to know when mail is plain text (thanks to class.emailtemplate.php research )
Then concatenate string if plain text or use setFooter when HTML mode is active.
Working perfeclty! Thank you @R_J
You need to publish this plugin I guess many people will find it useful, addind a config menu to custommize the text line and call it "The email footer plugin"