Back to vBulletin 3.6 Add-ons

Send html OR plain text emails per user
Mod Version: 1.00, by phart

This modification is in the archives.
vB Version: 3.6.4 Rating: (1 vote - 4.00 average) Installs: 9
Released: 22 Feb 2007 Last Update: 23 Feb 2007 Downloads: 73
Not Supported Code Changes Additional Files  

This edit will allow users to select email format preference when they sign up or edit their profile. It also defaults to plain text if no choice is found to prevent from sending people html that did not clearly ask for it.

You can also edit the header and footer content of the mails using an external file so the actual system message is untouched.

First create a new user profile field:

admincp -> User Profile Fields -> Add New User Profile Field -> single Selection Radio Buttons

Title: Email Preference
Description: blank
Items per Line:0
Options: ( one per line )
Plain Text
HTML

Set Default: Yes ( makes plain text default )
Field required: no, but display at registration
Editable by user: Yes
Searchable: yes
Show on member list: yes
[rest of options as is]

Click Save

------------------------------------
Next create a file called email_headers_and_footers.php and paste the following in it:

PHP Code:
<?php
$html_header_for_email 
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
        <html><head><style type=\"text/css\"><!--
                        your css here
                    -->
                    </style></head><body><table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
                    <tr>
                        <td>
                        <!--BEGIN VIEW ONLINE MESSAGE-->
                            <div class=\"_notice\">
                                If you don't see images, right click the missing image to accept image downloads: 
                                <img src=\"http://www.yoursite.com/email/acceptImages.gif\" border=\"1\" width=\"120\" height=\"25\" alt=\"Right click to accept images\" />
                                <br />
                                <br />
                            </div>  
                        <!--END VIEW ONLINE MESSAGE-->    
                        <div>
                            <div>
$subject<br /></div>
                            <!--BEGIN TOPIC-->
                                <div>"
;
$html_footer_for_email "<p><img src=\"http://www.yoursite.com/email/email_.png\" alt=\"Logo\" width=\"194\" height=\"60\" border=\"0\" /><br /><br />
                                    At your site, we do not send unsolicited emails. To change your email settings, or update your account please edit your settings in the user control panel once logged in at <a href=\"http://forums.yoursite.org\">forums.yoursite.org</a>. </p>
                                    </div>
                                </div></td></tr></table></body></html>\r\n\r\n"
;


$text_header_for_email "$subject\r\n\r\n";
$text_footer_for_email "\r\n\r\nAt your site, we do not send unsolicited emails. To change your email settings, or update your account please edit your settings in ";
$text_footer_for_email .= "the user control panel once logged in at forums.yoursite.org.";
?>
Save this file in the /includes directory.

Next Edit the class_mail.php file in /includes.

Just above the start() function add this ( about line 138 ):

PHP Code:
    /*
    * collects info about the user the email is going to
    * and sets the type of email according to field7
    * to change the field checked set $fieldNumber to 
    * match your needs
    * $useremail -> the $toemail value in function start() below
    * $fieldNumber -> filed in userfield table to check for
    */
    
function determine_email_format($useremail) {
        global 
$vbulletin;
        
$fieldNumber "17";
        
        
$result $vbulletin->db->query_first("SELECT userid FROM " TABLE_PREFIX "user WHERE email = '" $useremail "'");
        if (!empty(
$result)) {
            
$thisuserid $result['userid'];
        } else {
            
$thisuserid "failed";
        }
        
        if(
$thisuserid != "failed") {
            
$fieldresult $vbulletin->db->query_first("SELECT field" $fieldNumber " FROM " TABLE_PREFIX "userfield WHERE userid = '" $thisuserid "'");
            if (!empty(
$fieldresult['field' $fieldNumber])) {
                
$email_format $fieldresult['field' $fieldNumber];
            } else {
                
// if we cant find email type just use text to be safe
                
$email_format "plain text";
            }
        } else {
            
// type isnt set yet, send plain text to be safe
            
$email_format "plain text";
        }
        
        return 
$email_format;
        
    } 
The $fieldNumber variable needs to match the ID of the profile field you created above.

PHP Code:
$fieldNumber "17"
Next comment out these lines in the start() function:

PHP Code:
$headers .= 'MIME-Version: 1.0' $delimiter;
$headers .= 'Content-Type: text/plain' iif($encoding"; charset=\"$encoding\"") . $delimiter;
$headers .= 'Content-Transfer-Encoding: 8bit' $delimiter;
$headers .= 'X-Priority: 3' $delimiter;
$headers .= 'X-Mailer: vBulletin Mail via PHP' $delimiter
and in the start() function below
PHP Code:
$headers .= preg_replace("#(\r\n|\r|\n)#s"$delimiter$uheaders);
unset(
$uheaders); 
add

PHP Code:
$emailtype strtolower(vB_Mail::determine_email_format($toemail));
include(
"email_headers_and_footers.php");
/* html email headers begin */
if($emailtype == "html") {
    
// build html email headers
    
$headers .= 'MIME-Version: 1.0' $delimiter;
    
$headers .= 'Content-Type: text/html' iif($encoding"; charset=\"$encoding\"") . $delimiter;
    
$headers .= 'Content-Transfer-Encoding: 8bit' $delimiter;
    
$headers .= 'X-Priority: 3' $delimiter;
    
$headers .= 'X-Mailer: vBulletin Mail via PHP' $delimiter;
    
// set body for html mail
    
$bodyMail "$html_header_for_email$message$html_footer_for_email";
} else if(
$emailtype == "plain text") {
    
// build plain text email headers
    
$headers .= 'MIME-Version: 1.0' $delimiter;
    
$headers .= 'Content-Type: text/plain' iif($encoding"; charset=\"$encoding\"") . $delimiter;
    
$headers .= 'Content-Transfer-Encoding: 8bit' $delimiter;
    
$headers .= 'X-Priority: 3' $delimiter;
    
$headers .= 'X-Mailer: vBulletin Mail via PHP' $delimiter;
    
$message strip_tags($message);
    
$bodyMail "$text_header_for_email$message$text_footer_for_email";

and then comment and replace this line:

PHP Code:
$this->message $bodyMail;
/*$this->message = $message;*/ 
This will add the profile field in register and user control panel as well as admin cp. The HTML for the header and footer of the mail is totally up to you of course.

This is my first time posting a mod, so I apologize if its not in the right format.

So now anytime the system sends an email, it checks the users preference and sends html or plain text accordingly.

Download

This modification is archived, downloads are still allowed.

File Type: %1$s class_email_added_function.txt (1.2 KB, 31 downloads)
File Type: %1$s edited_start_function.txt (5.8 KB, 34 downloads)
File Type: %1$s email_headers_and_footers.php (1.6 KB, 34 downloads)

Screenshots

Click image for larger version
Name:	choice.png
Views:	141
Size:	36.5 KB
ID:	60903   Click image for larger version
Name:	admin_option.png
Views:	129
Size:	37.8 KB
ID:	60904  

Similar Mods

Fix for problem posting HTML entities as plain text vBulletin 3.5 Add-ons
Fix for problem posting HTML entities as plain text vBulletin 3.0 Full Releases

vblts.ru supports vBulletin®, 2022-2024