PDA

View Full Version : [vB v2.2.1] SMTP Support and MIME/HTML Emails!


fastforward
01-03-2002, 10:00 PM
This hack adds additional email features to vB 2.2.1

Allows you to send mail via SMTP instead of using the site wide settings
in your php.ini.
Allows you to send email as MIME/HTML with a plain text part allowing
almost all email clients to view the email in a readable format.
Any combination of the above are selectable via the control panel.

Latest version is 20020106

I initially wrote this to enable SMTP email and get around a problem I was having with my emails not being delivered to AOL users. I believe it must have something to with my php.ini. But then I decided I might as well expand on the idea.

In addition to the SMTP capability, this hack adds MIME/HTML capablities to vB. There is no need to worry whether a user can read HTML. You simply send send both versions in the same MIME mail. The email client will display whatever it can or wants.

I've noticed a couple of hacks that allow you to send HTML email from vB. Both of them simply add the Content Type: text/html in the header and send it as normal. This is all very well for a handful of the newest email clients, but if the recipient can't or doesn't want to recieve HTML mail, the message is almost unreadable. The two obvious solutions are to either make it user selectable or send both types in MIME format. This hack does both. It allows users to select whether they receive HTML or text emails via the user control panel but sends MIME as default.

This approach required a quite lot of code changes, so for those of you don't want the headache of changing all the code, this hack has two levels of install. You can do the simple install first, which gives most of the features without the user selectable option. If you like it, you can do the second level install later.

Full instructions for the second level install are in the attached zip.



Overview:
There are two levels of installation to this hack. The first method is simple. The SQL commands will make the global settings visible in the control panel under 'vBulletin Options => Email Options' section. It also creates an example template for testing the new reply notifications.

The uploaded file contains all the functions/classes required.

It is then just a case of adding a require() in both global.php files and replacing the existing mail() calls in the code with the new mime_mail(). All the other parameters in the function call remain the same. Can't get much easier than that! At this level, you will be able to opt whether to send mail via SMTP or the method specified in your existing php.ini file. HTML mail can also be sent from any form that accepts input, ie. the mass emailer. Simply enter HTML in the form and the hack will generate the plain text automatically and send a complete MIME message to all recipients. HTML is either globally on or off via the control panel with this level of installation.

The second level of installation requires that you add a few more parameters to the mime_mail() function in addition to what was there originally. This allows you to use HTML templates to send mail where appropriate. It also allows the user to select whether they should recieve HTML mail regardless of your CP settings. You can make these changes without creating additional custom templates immediately. Everything will work as in the basic install. You can then add the templates at your leisure by creating a new one with the same name and '_html' at the end. There a few more lines of code to add for this level of install but it's still pretty straightforward.


The mime_mail() function can be used in other scripts/hacks and takes the
following parameters:
Recipients email address
Email subject
Plain text message (optional) defaults to auto generated from HTML message
From Header (optional) defaults to $bbtitle Mailer <$webmasteremail>
HTML Message (optional) defaults to auto generated from text message
Force Text Only (optional) defaults to FALSE

If either the plain text or the html parameter is null, the correct format is generated automatically from the other one. Obviously at least one of the parameters must be there. :)



Quick Example:
These two lines will replace the existing mail() function and provide
HTML mail via a new template you created. It will also use SMTP if
specified in the control panel.

eval("\$emailmsghtml =
\"".gettemplate("email_notify_html",1,0)."\";");
mime_mail($touser[email],
$emailsubject,
$emailmsg,
$emailmsghtml);

nuno
01-04-2002, 05:09 AM
many tx Paul
wonderful hack

PS: will this be compatible with bira's Send Random Password instead of Activation Code Hack?
tia ;)

fastforward
01-04-2002, 05:19 AM
Originally posted by nuno
many tx Paul
wonderful hack

PS: will this be compatible with bira's Send Random Password instead of Activation Code Hack?
tia ;)
I don't see why not. The interface to this hack is really just a replacement for the mail() call, so any thing that sends mail should be able to use this.

Either way... if it's not compatible, I'll make it so :)

(shuffles off to check Bira's hack)

fastforward
01-05-2002, 03:14 AM
This hack has been updated.

It's now fully featured and allows users to override your control panel setting as to whether they should accept MIME/HTML mail.

The documentation has been updated and completed with detailed instructions on editing all the mail() calls to support HTML templates.

There are some changes to the parameter list for the mime_mail() function call, so if you've installed it already, you'll need to revisit the code changes. Any future updates should be limited to the included classes and won't affect the code changes.

In short... it's done :)

Please let me know if you come across any bugs. It's very difficult to fully test this kind of hack without emailing hundreds of different people.

nuno
01-05-2002, 03:21 AM
okie dokie Paul
i'll test this tomorrow
*too tired bed time*

nuno
01-06-2002, 04:11 PM
hi Paul
i cant even install this hack to fully test it
Warning: Cannot add header information - headers already sent by (output started at vb\admin\mime_html_smtp.inc:948) in vb\admin\functions.php on line 1491

i cant even login to admin CP now *sux* :(

nuno
01-06-2002, 04:27 PM
after hitting login i get this:

Warning: Cannot add header information - headers already sent by (output started at vb\admin\mime_html_smtp.inc:948) in vb\admin\functions.php on line 1491

Warning: Cannot add header information - headers already sent by (output started at vb\admin\mime_html_smtp.inc:948) in vb\admin\functions.php on line 1491

Warning: Cannot add header information - headers already sent by (output started at vb\admin\mime_html_smtp.inc:948) in vb\admin\global.php on line 139

Warning: Cannot add header information - headers already sent by (output started at vb\admin\mime_html_smtp.inc:948) in vb\admin\global.php on line 165

Hang on a sec

:(
then i get kicked to login page again :confused:

nuno
01-06-2002, 04:31 PM
whoa found it
you need to remove last couple of lines at mime_html_smtp.inc file just after ?> :)

nuno
01-06-2002, 05:07 PM
arrrghhh i guess i'm blind
where do i set it to send HTML instead of plain text?

fastforward
01-06-2002, 05:15 PM
Originally posted by nuno
arrrghhh i guess i'm blind
where do i set it to send HTML instead of plain text?
In The mail control panel select 'vBulletin Options' in the Side Panel, then '[Email Options]' at the top of that page.

nuno
01-06-2002, 05:22 PM
well
there are 7 new fields at email options:

Use SMTP
SMTP Host
SMTP Port
This Hostname
Requires Authorization
SMTP Username
SMTP Password


where's the field to specify something like
Send Emails using MIME/HTML? :confused:

fastforward
01-06-2002, 05:31 PM
Ahh... oops! :o

The user selectable option is in the User CP along with the other email notification settings, but it seems I left out the main control panel option.

The way it is now, means unless the user selects 'Text only emails' in their options, MIME will be sent by default.

Give me 10 minutes and I'll add the master switch to the main CP.

nuno
01-06-2002, 05:32 PM
okie dokie

fastforward
01-06-2002, 05:44 PM
Just run this to add the missing column

INSERT INTO setting VALUES (300,11,'Use MIME/HTML','html_use','1','This will send mail as MIME/HTML unsless the user selects otherwise.','yesno',5);

Everything else is already in place.

nuno
01-06-2002, 05:53 PM
*dang*
no mails are sent now :(

fastforward
01-06-2002, 06:03 PM
Originally posted by nuno
*dang*
no mails are sent now :(
No errors? or blank pages? Whic options were you using. Does it work if you don't use SMTP?

nuno
01-06-2002, 07:13 PM
only works if i set "This will send mail as MIME/HTML unsless the user selects otherwise" to NO

fastforward
01-06-2002, 07:33 PM
Originally posted by nuno
only works if i set "This will send mail as MIME/HTML unsless the user selects otherwise" to NO
I can't seem to duplicate this error. Which email isn't it sending and what are the user settings for the user that should get it?

nuno
01-06-2002, 07:42 PM
i'm testing it with sendtofriend now
user has Text Only Emails set to NO
Under CP i have
Use MIME/HTML set to YES
Use SMTP set to Yes

If i set MIME/HTML to Yes under CP the board crashes everytime that mime_mail is called, like sendtofriend, lost password recovery, new registration, mass mail etc...
No errors are generated, the board just stalls out :(

fastforward
01-06-2002, 07:49 PM
Hmm.. Doesn't sound good. What version of PHP are you using?
I'm using 4.0.6 and I've just tried your exact settings plus countless other combinations and I can't duplicate the error.

Double check the changes you made in sendtofriend.php. It should look like this:

// START MIME/HTML/SMTP HACK
eval("\$messagehtml = \"".gettemplate("email_sendtofriend_html",1,0)."\";");
mime_mail($sendtoemail,$emailsubject,$message,"From: \"$bbtitle Mailer\" <$webmasteremail>",$messagehtml);
// END MIME/HTML/SMTP HACK

Note: the html template does NOT need to exist even if you select MIME/HTML in the control panel.

nuno
01-06-2002, 07:55 PM
PHP Version 4.1.0.
I'm running Apache Version 1.3 and IIS5 Default SMTP Server.

fastforward
01-06-2002, 08:02 PM
Originally posted by nuno
PHP Version 4.1.0.
I'm running Apache Version 1.3 and IIS5 Default SMTP Server.
Is Apache on Windows too, or just the SMTP server? I haven't tested this with Windows.

If you still want to keep trying with this, could you add a debug line in mime_html_smtp.inc file in the mime_mail() function to identify the point at which it fails?

Put
echo "DEBUG\n"; exit;
at the first line then keep moving it down until it no longer shows up.

I'll understand if you don't have the time :)

nuno
01-06-2002, 08:06 PM
yup Apache and SMTP Server :)
ok lets start then ;)

nuno
01-06-2002, 08:09 PM
Warning: Missing argument 6 for mime_mail() in vb\admin\mime_html_smtp.inc on line 16
DEBUG

fastforward
01-06-2002, 08:26 PM
Originally posted by nuno
Warning: Missing argument 6 for mime_mail() in vb\admin\mime_html_smtp.inc on line 16
DEBUG
Change the first line of the mime_mail() functin to this

function mime_mail ($tomail, $subj, $txtmsg='', $from='', $htmlmsg='', $textonly=FALSE) {

nuno
01-06-2002, 08:44 PM
hmm
should i stop IIS5 SMTP Server?

fastforward
01-06-2002, 08:49 PM
Originally posted by nuno
hmm
should i stop IIS5 SMTP Server?
When? why?
This hack still needs a real SMTP server to be available. It doesn't send mail directly to the recipients remote mail server.

nuno
01-06-2002, 09:00 PM
i c
dunno whats wrong with my settings, but i cant make this hack to work with my server :(
i'm forced to uninstall it :(
tx 4 all your help Paul :)

chaz7979
01-11-2002, 12:13 AM
I just want to set up my board so that the email notify mails go out in html so html links can be read. If people don't have html they will jsut see the code and be able to read the rest of the email text right?

If so How can I set up the board to do that? Should be a matter of adding a MIME header to the mail code but I don't know where that is. Any help you could give me would be great.

fastforward
01-11-2002, 12:27 AM
Originally posted by chaz7979
I just want to set up my board so that the email notify mails go out in html so html links can be read. If people don't have html they will jsut see the code and be able to read the rest of the email text right?

If so How can I set up the board to do that? Should be a matter of adding a MIME header to the mail code but I don't know where that is. Any help you could give me would be great.
There's a bit more to it than adding a MIME header. You need to actually encode the HTML using base64. All the necessary functions are available in php, or you can use one of the php classes distributed at zend.com, or you can use this hack and only change the mail() call to mime_mail() in the relevent file that sends notify messages (functions.php).

chaz7979
01-11-2002, 02:54 AM
So if I just do the first 2 steps (simple install) I should be all set?

I have one concern 2. c. says

If you are doing a full install, you can skip this:

Go through the vB files and replace all occurances of
'mail(' with 'mime_mail('

All the files? There is a lot of files that make up VB. Do we really have to go through every single file? How many instances are there?

fastforward
01-11-2002, 03:10 AM
Originally posted by chaz7979
So if I just do the first 2 steps (simple install) I should be all set?

I have one concern 2. c. says

If you are doing a full install, you can skip this:

Go through the vB files and replace all occurances of
'mail(' with 'mime_mail('


All the files? There is a lot of files that make up VB. Do we really have to go through every single file? How many instances are there?
That really means 'Go through the vB files and replace all occurances of mail().. for which you wish to use the new MIME or SMTP functionality.'
The full install instructions actually list all the bits that need changing. That will include all the mail() calls. There's not really that many compared to some of the hacks here.

In your case, you should be able to just do the simle install (ie. steps 1 & 2. then follow the step in the instructions that changes the mail() call in functions.php which is 6a.

A) ADMIN/FUNCTIONS.PHP

OLD CODE
--------
mail($touser[email],$emailsubject,$emailmsg,"From: \"$bbtitle Mailer\" <$webmasteremail>");

NEW CODE
--------
// START MIME/HTML/SMTP HACK
eval("\$emailmsghtml = \"".gettemplate("email_notify_html",1,0)."\";");
mime_mail($touser[email],$emailsubject,$emailmsg,"From: \"$bbtitle Mailer\" <$webmasteremail>", $emailmsghtml, $touser[emailtextonly]);
// END MIME/HTML/SMTP HACK

Don't forget to create a template called email_notify_html.

chaz7979
01-11-2002, 07:28 AM
Originally posted by fastforward

Don't forget to create a template called email_notify_html.

That's not in step one and 2...is it?

By the way thanks fo your help :-)

ElecEagle
02-27-2002, 12:39 AM
Was wondering if anyone could help me with the following error I'm getting trying to send email to a member after installing the SMTP Hack (full install) by fastforward?

Database error in vBulletin 2.2.2:

Invalid SQL: SELECT username,email,showemail, FROM user WHERE userid='1'
mysql error: You have an error in your SQL syntax near 'FROM user WHERE userid='1'' at line 1

mysql error number: 1064

Date: Tuesday 26th of February 2002 08:36:21 PM
Script: http://www.ellardobluth.homelinux.net/forum/forum/member.php
Referer: http://www.ellardobluth.homelinux.net/forum/member.php?action=mailform&userid=1

ElecEagle
02-27-2002, 02:02 AM
Just so I'm being thorough, here's the code I believe is causing the error in members.php:

// START MIME/HTML/SMTP HACK
$destuserinfo=$DB_site->query_first("SELECT username,email,showemail,$emailtextonly FROM user WHERE userid='$destuserid'");
// END MIME/HTML/SMTP HACK

Anyone see any problems with it?

ElecEagle
02-27-2002, 10:08 AM
Database error in vBulletin 2.2.2:

Invalid SQL: SELECT DISTINCT user.email,.emailtextonly FROM moderator,user WHERE moderator.userid=user.userid AND forumid IN (2,1,-1) AND (newthreademail=1 OR newpostemail=1)
mysql error: You have an error in your SQL syntax near 'FROM moderator,user WHERE moderator.userid=user.userid AND forumid IN (2,1,-1) A' at line 1

mysql error number: 1064

Date: Wednesday 27th of February 2002 06:07:30 AM
Script: http://www.ellardobluth.homelinux.net/forum/forum/newthread.php
Referer: http://www.ellardobluth.homelinux.net/forum/newthread.php?action=newthread&forumid=2

==================

think I'll just give up on this hack and try to revert it back out. Sounds like a good thing ...but can't get any help on it.

fastforward
02-27-2002, 12:42 PM
Your problem is with the $emailtextonly variable. Are you sure you added the column with the 'DEFAULT 1' option? Also, check the template modifications for the CP to make sure it defaults to 1.

Do a query on the user table and see if you have any null values for the emailtextonly column.

Jawelin
03-11-2002, 03:08 PM
Originally posted by fastforward
[b]This hack adds additional email features to vB 2.2.1

Allows you to send mail via SMTP instead of using the site wide settings
in your php.ini.
Allows you to send email as MIME/HTML with a plain text part allowing
almost all email clients to view the email in a readable format.



Excuse the bump but it's a nice feature.
Just a question: is it possible send attachments with this kind of mail ?
Standard MIME should permit that... How could I send - for example - something attached to the webmaster email under certain conditions ?

Thanks

x69
04-20-2002, 09:45 PM
I've been holding off on upgrading to 2.2.2+ b/c i was waiting on a new version hack of this to come out.. Does anyone know if this works on 2.2.5? This is the only hack i've ever installed and it kinda scares me when i do anything like this.. I really wish SMTP support was included into vbulletin without having to do any hacks. If anyone has tried this in 2.2.5 plz let me know, Thanks
-X69

AzzKickr
11-23-2002, 02:01 AM
just installed it on 228 and i can't even log in to admin CP, have nothing to delete on mime_html_smtp.inc after <? :(
what should i do? help me please :( :banana:

Tobad
12-10-2002, 12:22 AM
Hi,
Just found this hack. Installed it on my Vbulletin forum which is running on Powweb hosting.

Quick Info:
I use to run my own server before and never had any problems. Certain things made me go with a host. To make a long story short, they won't update the PHP.INI to match my SMTP server settings because I'm on the shared server. Right now it just says LOCALHOST in the PHP.INI but the SMTP server is totally separate machine.

I installed this hack and most of the Email To options work now. For some reason, the only ones that seem not to send any emails are the Email Password To User and when a new user registers (the confirmation). Am I missing something? I went through every file (all of them) and made sure that I changed the mail( to 'mime_mail(.

I'm running Vbulletin 2.2.9 right now. At this moment this hack seems to be my only choice. Any help would be appreciated. I'll supply any info needed.

Thanks!

fastforward
12-10-2002, 12:49 AM
Originally posted by Tobad
Hi,
Just found this hack. Installed it on my Vbulletin forum which is running on Powweb hosting.

Quick Info:
I use to run my own server before and never had any problems. Certain things made me go with a host. To make a long story short, they won't update the PHP.INI to match my SMTP server settings because I'm on the shared server. Right now it just says LOCALHOST in the PHP.INI but the SMTP server is totally separate machine.

I installed this hack and most of the Email To options work now. For some reason, the only ones that seem not to send any emails are the Email Password To User and when a new user registers (the confirmation). Am I missing something? I went through every file (all of them) and made sure that I changed the mail( to 'mime_mail(.

I'm running Vbulletin 2.2.9 right now. At this moment this hack seems to be my only choice. Any help would be appreciated. I'll supply any info needed.

Thanks!
I must admit I'm not actually using this hack myself anymore. I'll dig it out and see if there's anything strange about that particular function.

Tobad
12-10-2002, 01:04 AM
I would appreciate that man. Right now I'm stuck. Powweb support told me to try to put a .htaccess file with this in it:

php_value sendmail_from mail.chicagogamers.com

When I input this to the forums dir as instructed by the tech support...it just errors out my forum.

This is frustrating already as everything else works like a charm with this host.

I searched all over the place and this hack seems to be the only solution so far.

Tobad
12-10-2002, 04:23 AM
OK,
I re-read all the post here in this thread and then I noticed the little thing you mentioned about replacing the mail( and the mail (. I originally replaced only the mail(. This is why everything else worked just fine, but the mail ( didn't.

I have made the changes now and everything is working great. So just in case someone is looking for solution being on a shared SMTP, your hack is it.

Thank you.