Version: 1.00, by phart
Developer Last Online: Sep 2007
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";
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:
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.