Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.6 > vBulletin 3.6 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Send html OR plain text emails per user Details »»
Send html OR plain text emails per user
Version: 1.00, by phart phart is offline
Developer Last Online: Sep 2007 Show Printable Version Email this Page

Category: Profile Enhancements - Version: 3.6.4 Rating:
Released: 02-21-2007 Last Update: 02-22-2007 Installs: 9
Code Changes Additional Files  
No support by the author.

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.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 02-23-2007, 12:42 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

phart,

you will need to upload files of modification to get maximum results eg. create email_headers_and_footers.php and upload it
Reply With Quote
  #3  
Old 02-23-2007, 01:05 PM
phart phart is offline
 
Join Date: Dec 2006
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Princeton,

Ive uploaded the added function for class_email.php and my edited start function for class_email.php as well as the email_headers_and_footers.php.
Reply With Quote
  #4  
Old 02-23-2007, 01:08 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank you ... you can edit your Modification Settings via https://vborg.vbsupport.ru/editpost....post&p=1188490
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:28 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.11472 seconds
  • Memory Usage 2,280KB
  • Queries Executed 17 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (3)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete