PDA

View Full Version : HTML welcome-email code


NickyDee
03-02-2011, 06:24 PM
I’m trying to make a plugin that will enable an HTML ‘welcome email’ when a user signs up. The problem seems to be that the $headers string is set to 'Content-Type: text/plain' and it needs to be 'Content-Type: text/html'.

There are already plugins that let admins send HTML emails to users that use this code to get around the problem:

if ($vbulletin->userinfo['usergroupid'] == 6)
{
if(strlen($message) != strlen(strip_tags($message)))
{
$headers = str_replace('Content-Type: text/plain', 'Content-Type: text/html', $headers);
}
}

So my question – can anyone suggest how I might adapt this to allow HTML welcome messages as well?

I will of course bundle it up into a plugin for everyone to use once it is complete.

--------------- Added 1299104905 at 1299104905 ---------------

Update:

Okay I've made some progress. The problem appears to be with the conditional which only works for adminCP emails sent from "users --> send email to users".

if ($vbulletin->userinfo['usergroupid'] == 6)

Removing the conditional would cause problems since many default vbulletin emails are not fully HTML formatted but contain some basic HTML tags. This would send them as fully HTML formatted (and they would end up all screwwed up because carriage returns are ignored in HTML emails).

So long story short... I need an additional condition that figures out whether this is the 'welcome email' or some other email. Then I can plug it in like this;

if ($vbulletin->userinfo['usergroupid'] == 6 || welcomemail_conditional == true)
{...

...}



Then we will have adminCP HTML emails AND HTML welcome emails but not any other emails (like forgotten password etc.)

--------------- Added 1299145970 at 1299145970 ---------------

Further update:

I have made a solution that works for me, but which isn't dynamic enough to be packaged into a plugin that will work for everyone. What you need to do is set your $vbphrase[welcomemail] phrase to something specific, like "Thanks for joining Sitename". Then edit the code below as needed:


if ($vbulletin->userinfo['usergroupid'] == 6 || $subject == 'Thanks for joining Sitename')
{
if(strlen($message) != strlen(strip_tags($message)))
{
$headers = str_replace('Content-Type: text/plain', 'Content-Type: text/html', $headers);
}
}


This will do two things;

Any message you send from users --> send email to users that contains HTML will be formatted with the 'Content-Type: text/html' header.
The welcome email will be formatted as HTML

JamesUK
07-24-2012, 01:23 PM
any indication of what file this needs to be added to so we can allow html emails with the welcome msg and in turn add a logo image.

Thanks

I.M.O.G.
10-24-2012, 02:41 AM
It isn't a file modification, its a plugin. So you need to go to plugin manager, add new plugin, and use the hook "mail_send". Hope that helps and is accurate. :)