Inserting isHTML in mosMail/JMail

Locked
caleb2001r
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 114
Joined: Mon Sep 05, 2005 6:07 am

Inserting isHTML in mosMail/JMail

Post by caleb2001r » Mon May 05, 2008 4:43 pm

First of all, thank you so much for any help in advance! :)

Here's the coding I'm working with; it's for a component called "Member Care System".

Code: Select all

<?php
/**
* Member Care System for Joomla
*
* @package MCS
* @author Mohamed Abdelaziz
* @copyright Mohamed Abdelaziz <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*
*/
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

global $mosConfig_frontend_login;

require_once( $mainframe->getPath( 'front_html' ) );
require_once( $mainframe->getPath( 'class' ) );

if( !@include_once( $mosConfig_absolute_path ."/administrator/components/com_mcs/lang/$mosConfig_lang.php" ) ) {
include_once( $mosConfig_absolute_path ."/administrator/components/com_mcs/lang/english.php" );
}

switch( $task ) {
case 'sendEmail':
sendEmail( $option );
break;
default:
resendEmailForm( $option );
break;
}

function resendEmailForm( $option ) {
global $mainframe;

$mainframe->SetPageTitle(_PROMPT_RAEMAIL);

HTML_mcs::resendEmailForm($option);
}

function sendEmail( $option ) {
global $database, $mosConfig_useractivation;
global $mosConfig_live_site, $mosConfig_sitename;
global $mosConfig_mailfrom, $mosConfig_fromname;

// simple spoof check security
josSpoofCheck();
$config = new MCSConfig($database);
$config->load(1);

$_live_site = $mosConfig_live_site;
$_sitename = $mosConfig_sitename;
$row = '';
$cb_installed = $config->cb_installed;
$message = $config->rae_message;
$subject = $config->rae_subject;
$subject = html_entity_decode($subject, ENT_QUOTES);
$tags = array("[NAME]","[UNAME]","[SITENAME]","[LIVESITE]","[ALINK]","<br />");
$tagsValues = array(" "," ",$mosConfig_sitename,$mosConfig_live_site," "," ");

// check if Global Config `mailfrom` and `fromname` values exist
if ($mosConfig_mailfrom != '' && $mosConfig_fromname != '') {
$adminName2 = $mosConfig_fromname;
$adminEmail2 = $mosConfig_mailfrom;
} else {
// use email address and name of first superadmin for use in email sent to user
$query = "SELECT name, email"
. "\n FROM #__users"
. "\n WHERE LOWER( usertype ) = 'superadministrator'"
. "\n OR LOWER( usertype ) = 'super administrator'"
;
$database->setQuery( $query );
$rows = $database->loadObjectList();
$row2 = $rows[0];

$adminName2 = $row2->name;
$adminEmail2 = $row2->email;
}

// ensure no malicous sql gets past
$checkusername = mosGetParam( $_POST, 'checkusername', '' );
$checkusername = $database->getEscaped( $checkusername );
$confirmEmail = mosGetParam( $_POST, 'confirmEmail', '');
$confirmEmail = $database->getEscaped( $confirmEmail );

$query = "SELECT id"
. "\n FROM #__users"
. "\n WHERE username = '$checkusername'"
. "\n AND email = '$confirmEmail'"
;
$database->setQuery( $query );
if (!($user_id = $database->loadResult()) || !$checkusername || !$confirmEmail) {
mosRedirect( "index.php?option=$option&task=resendEmail&mosmsg="._ERROR_RAEMAIL );
}

if($cb_installed){
$query = "SELECT a.*, c.cbactivation"
. "\n FROM #__users AS a"
."\n INNER JOIN #__comprofiler AS c ON a.id = c.id"
."\n WHERE a.id=$user_id";
$database->setQuery( $query );
$database->loadObject($row);
} else {
$row = new mosUser( $database );
$row->load( $user_id );
}
if (($cb_installed && !($row->cbactivation)) || (!$cb_installed && !($row->activation))) {
mosRedirect( "index.php?option=$option&task=resendEmail&mosmsg="._ERROR_RAEMAIL );
}

if ($mosConfig_useractivation == 1){
if($cb_installed)
$tagsValues[4] = $mosConfig_live_site."/index.php?option=com_comprofiler&task=confirm&confirmcode=".$row->cbactivation;
else
$tagsValues[4] = $mosConfig_live_site."/index.php?option=com_registration&task=activate&activation=".$row->activation;
}
$tagsValues[0] = $row->name;
$tagsValues[1] = $row->username;
$message = str_replace($tags, $tagsValues, $message);
$message = html_entity_decode($message, ENT_QUOTES);
// Send email to user
mosMail($adminEmail2, $adminName2, $row->email, $subject, $message,1);


mosRedirect( "index.php?option=$option&mosmsg=". _REMAIL_SENT );
}

?>

This is the part of the code that sends the email, but the problem is is that it sends it as plain text and not HTML. The <br /> tags are stripped from $message and it sends an email like one long message.

I've been hinted to use the isHTML function, but can someone please point out where I should place this to get it to work?

FYI: The str_replace replaces some tags with site constants like user name and site name.

PS. Will changing mosMail to JMail hurt anything? I'd like to help improve this component for support for Joomla 1.5.

Locked

Return to “Joombie Coding Q/A”