HTML mail over plain text

9 Sep 2017
#1
Hello,

I am struggling with this issue for quit a while now ...
I would like to get rid of the boring plain text automated mailing which is included into mybb.

I attended the question on the mybb community forums, but nobody seemed to get an answer to it ... In this stage I can only change the mail templates but not the way how it looks like because CSS and HTML markup is excluded in plain text mail headers.

kind regards
Shade 10 Sep 2017
#2
A core edit is needed for this. Open inc/functions.php, find:

my_mail($email['mailto'], $email['subject'], $email['message'], $email['mailfrom'], ""$email['headers'], true); 
Replace with:

if (strpos($email['message'], '<br />') === false && strpos($email['message'], '<br>') === false) {
    
$email['message'] = nl2br($email['message']);
}

my_mail($email['mailto'], $email['subject'], $email['message'], $email['mailfrom'], ""$email['headers'], true'html'); 
I suggest you to use the awesome Patches plugin to keep track of core edits so you can easily upgrade your board without forgetting your custom edits.
zyra 10 Sep 2017
#3
I implemented the above code...
I am currently testing by posting replys to topics where I am abbonated with another registered account.. but nothing happens no mails are sent..
Is there maybe a more convenient way to test the mail function ?
Shade 10 Sep 2017
#4
Automated mails are sent by the task system, so you might need to wait till the task is unlocked and/or ran. You can send mails programmatically with the ACP tool "Mass mail".
zyra 10 Sep 2017
#5
Aha ok... does the mass mail also uses the same piece of adjusted code from you're earlier post?

Is it possible to retrieve the avatar url from a poster to put it in the mailtemplates? like the {2} stands for the name of the user who posted a reply to an abbonated topic ?
Shade 10 Sep 2017
#6
Yes, my_mail() is the main function used by MyBB for everything that concerns mails.

The avatar thing would require way too much work to figure it out for me at the moment, sorry.
zyra 10 Sep 2017
#7
Absolutely no problem m8!, you did already a lot by helping me out on this html mail template thing :)
Eldenroot 10 Sep 2017
#8
@zyra - can you please share your css and code? Or the screenshot how your emails look like? Thank you very much!

P.S. Same request and question as you on MyBB.com community forum but without reply :/
zyra 10 Sep 2017 Edited
#9
Hi eldenroot!
Yea it's h8full I am waiting for like 5months for this one to got solved... thank god shade helped us out! :D
Take a look to the screen and then tell me if you'd like the code ... maybe you think it's ugly [Image: Rc3XxJ4.png]

My other mail templates from other sections on my site looks like this:
[Image: xtBz8Wh.png]
Sadly I don't know how to get the avatar urls into the mybb mailtemplates :( ... perhaps I could make a query on the username each time it call's the coresponding mailtemplate ... something like :
$username = '{2}';
$sql = "SELECT avatar FROM mybb_users WHERE username ='$username'";
$result = $conn->query($sql);
$avatar = $result->fetch_assoc();

and then the avatar url would be stored in this variable: $avatar['avatar'] so that way I could use it in the mailtemp... however the problem starts out where I declare the $username variable ... only the number twoo within curly brackets will be saved and unfortunately not the actual username :(. And as I don'T know enough from this mailtemp. system I can't find a work around it.
Eldenroot likes this post
Eldenroot 11 Sep 2017
#10
It is amazing! Really nice! I would like to create something like Xenforo:
https://community.mybb.com/thread-212667.html

Can you please share your code or at least html template? I will try to adjust it for my needs, thank you in advance!