7 Replies - 458 Views - Last Post: 21 January 2012 - 09:58 PM

Topic Sponsor:

#1 thatgoogleguy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 26-May 11

RAW HTML Code being displayed instead of actual content - Joomla!

Posted 19 January 2012 - 08:11 PM

I'm trying to include more content into the registration email of my Joomla site. When I enter in HTML (in the en-GB_users.ini file) only raw HTML is shown. Furthermore when I edit the controller.php file (the file that calls that language file which is en-GB_users.ini and triggers the email sending function) I still get the raw HTML when the registration email is sent off.
function _sendMail(&$user, $password)
	{
		global $mainframe;

		$db		=& JFactory::getDBO();

		$name 		= $user->get('name');
		$email 		= $user->get('email');
		$username 	= $user->get('username');

		$usersConfig 	= &JComponentHelper::getParams( 'com_users' );
		$sitename 		= $mainframe->getCfg( 'sitename' );
		$useractivation = $usersConfig->get( 'useractivation' );
		$mailfrom 		= $mainframe->getCfg( 'mailfrom' );
		$fromname 		= $mainframe->getCfg( 'fromname' );
		$siteURL		= JURI::base();

		$subject 	= sprintf ( JText::_( 'Account details for' ), $name, $sitename);
		$subject2 = 'Preview of Power Parenting Courses';
		//$subject 	= html_entity_decode($subject, ENT_QUOTES);

		if ( $useractivation == 1 ){
			$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ),$name, $sitename, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $siteURL, $username, $password);
		} else {
			$message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
		}

		//$message = html_entity_decode($message, ENT_QUOTES);

		//get all super administrator
		$query = 'SELECT name, email, sendEmail' .
				' FROM #__users' .
				' WHERE LOWER( usertype ) = "super administrator"';
		$db->setQuery( $query );
		$rows = $db->loadObjectList();

		// Send email to user
		if ( ! $mailfrom  || ! $fromname ) {
			$fromname = $rows[0]->name;
			$mailfrom = $rows[0]->email;
		}

	JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);

I commented out the function html_entity_decode(); still with no luck. I've been working on this for nearly 6 hours and still can't find a way to display actual HTML content (besides a link) in the Joomla registration email. Any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: RAW HTML Code being displayed instead of actual content - Joomla!

#2 KuroTsuto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 42
  • View blog
  • Posts: 182
  • Joined: 13-February 09

Re: RAW HTML Code being displayed instead of actual content - Joomla!

Posted 19 January 2012 - 09:02 PM

Well my friend, I'm not familiar with Joomla but I had a sneaking suspicion that it had something to do with the headers that Joomla has been dispatching your emails with. Since the script you've provided doesn't appear to be playing with headers anywhere, I figured they must be set inside the JUtility::sendmail function. A quick Googling found me the method's documentation page.

Looks like there's a sixth $mode argument that defaults to FALSE, indicating that that email should be sent as plain text. Try this:
function _sendMail(&$user, $password)
	{
		global $mainframe;

		$db		=& JFactory::getDBO();

		$name 		= $user->get('name');
		$email 		= $user->get('email');
		$username 	= $user->get('username');

		$usersConfig 	= &JComponentHelper::getParams( 'com_users' );
		$sitename 		= $mainframe->getCfg( 'sitename' );
		$useractivation = $usersConfig->get( 'useractivation' );
		$mailfrom 		= $mainframe->getCfg( 'mailfrom' );
		$fromname 		= $mainframe->getCfg( 'fromname' );
		$siteURL		= JURI::base();

		$subject 	= sprintf ( JText::_( 'Account details for' ), $name, $sitename);
		$subject2 = 'Preview of Power Parenting Courses';
		//$subject 	= html_entity_decode($subject, ENT_QUOTES);

		if ( $useractivation == 1 ){
			$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ),$name, $sitename, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $siteURL, $username, $password);
		} else {
			$message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
		}

		//$message = html_entity_decode($message, ENT_QUOTES);

		//get all super administrator
		$query = 'SELECT name, email, sendEmail' .
				' FROM #__users' .
				' WHERE LOWER( usertype ) = "super administrator"';
		$db->setQuery( $query );
		$rows = $db->loadObjectList();

		// Send email to user
		if ( ! $mailfrom  || ! $fromname ) {
			$fromname = $rows[0]->name;
			$mailfrom = $rows[0]->email;
		}

	JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message, 1);



Note the extra argument at the end of JUtility::sendMail(). Evaluating to boolean TRUE, this should specify that you wish to send the email as HTML.

Good Luck!
Was This Post Helpful? 0
  • +
  • -

#3 thatgoogleguy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 26-May 11

Re: RAW HTML Code being displayed instead of actual content - Joomla!

Posted 19 January 2012 - 10:09 PM

Thanks KuroTsuto, but it didn't seem to work. =/ I'll go ahead and do some method inspection. I'm pretty sure others are having the same problem.
Was This Post Helpful? 0
  • +
  • -

#4 KuroTsuto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 42
  • View blog
  • Posts: 182
  • Joined: 13-February 09

Re: RAW HTML Code being displayed instead of actual content - Joomla!

Posted 19 January 2012 - 10:45 PM

Bummmmmeerrr!!! Sorry to hear it man :/ . You would happen to have a full email, headers and all on hand, would you?

EDIT:
Well, minus any personal information, of course ;)

This post has been edited by KuroTsuto: 19 January 2012 - 10:46 PM

Was This Post Helpful? 0
  • +
  • -

#5 thatgoogleguy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 26-May 11

Re: RAW HTML Code being displayed instead of actual content - Joomla!

Posted 19 January 2012 - 11:38 PM

Here's a snippet of the HTML code that's displayed in the email instead of the actual content.
echo
"<META HTTP-EQUIV='Content-Type' CONTENT='text/html;charset=iso-8859-1'>
<html><body>	
	<div style='text-align:center;margin:0px;background-color:#222;'>
		<div style='background-color:#222;text-align:center;margin:0px;'>
			<table border='0' cellspacing='0' cellpadding='0' width='600' style='background-color: rgb(0, 0, 0); margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; text-align: left; color: rgb(102, 102, 102); font-family: Helvetica; '>
				<tbody><tr>
					<td colspan='3' style='background-color: rgb(34, 34, 34); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; color: rgb(255, 255, 255); font-size: 11px; font-weight: normal; text-align: center; text-transform: lowercase; font-family: Arial;'>
						
						<span>Email not displaying correctly? <a rel'nofollow' target='_blank' href='http://us2.campaign-archive1.com/?u=1401b99c3191f0c4fbdbe238b&amp;id=739ffcc4dc&amp;e=fb9ea2e854' style='color:#fff;text-decoration:underline;font-weight:normal;'>View it in your browser.</a></span>
						
					</td>
				</tr>
				<tr>
					<td colspan='3'><div style='text-align: center; color: rgb(80, 80, 80); font-size: 14px; line-height: 150%; font-family: Arial; '>
	&nbsp;</div>
<div style='text-align:center;'>
	<br>

	<a rel='nofollow' target='_blank' href='http://***********?u=1401b99c3191f0c4fbdbe238b&amp;id=5a7eb1919c&amp;e=fb9ea2e854' style='color:#800000;text-decoration:underline;font-weight:normal;'><img alt='' src='http://gallery.mailchimp.com/1401b99c3191f0c4fbdbe238b/files/2_PPU_Attendance.jpg' style='line-height:100%;outline:medium none;text-decoration:none;display:inline;max-width:358px;border-width:0px;border-style:solid;width:800px;min-height:900px;'></a></div>

</td>
I've tried passing the email contents to a PHP variable and I've tried putting HTML within the method itself. What's really odd is that when I use PHP's mail() function I'm still delivered a text only formatted email using the controller file. (I've even tried passing header values using the PHP mail function, but no luck.) When I set up the mail function in an independent script such as send_this_email.php and use a CRON job to execute the script at a certain time I'm delivered an appropriate email with perfect formatting.
Was This Post Helpful? 0
  • +
  • -

#6 KuroTsuto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 42
  • View blog
  • Posts: 182
  • Joined: 13-February 09

Re: RAW HTML Code being displayed instead of actual content - Joomla!

Posted 20 January 2012 - 03:04 PM

Righto - your HTML looks solid, which is why I was curious about a full email... Particularly the "Content-Type" header.

One thing I've read about is that some code will use line-return characters in combination with, or instead of newline characters to concatenate email headers. Some email clients such as Gmail choke up if the headers weren't concatenated properly and will misinterpret the content type as a result.

I dug a little further, and as long as you're setting $mode to anything other than boolean FALSE, then we can disregard the Joomla controller being responsible for this problem as the Joomla JMail class never even touches the headers, directly. It inherits from the PHPMailer class. So if $mode is boolean TRUE, then your problem may well lie with PHPMailer.

PHPMailer is in and of itself a Google Code project, and while there are no issues listed specifically pertaining to your problem, one does mention consistent header anomalies.

There exists the possibility that your email client is gagging on improperly formatted headers. I might suggest attempting to open the email in several different clients. But again, examining the actual headers that are being dispatched is probably a solid debugging step at this point.
Was This Post Helpful? 0
  • +
  • -

#7 Lemur  Icon User is offline

  • OpenBSD Head
  • member icon

Reputation: 683
  • View blog
  • Posts: 2,519
  • Joined: 28-November 09

Re: RAW HTML Code being displayed instead of actual content - Joomla!

Posted 20 January 2012 - 04:26 PM

Why is the Meta information not inside the HTML tag and in a <head> section?
Was This Post Helpful? 0
  • +
  • -

#8 thatgoogleguy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 26-May 11

Re: RAW HTML Code being displayed instead of actual content - Joomla!

Posted 21 January 2012 - 09:58 PM

View PostLemur, on 20 January 2012 - 04:26 PM, said:

Why is the Meta information not inside the HTML tag and in a <head> section?

The meta information isn't need. When using a CRON job and sending off the template everything works fine.

View PostKuroTsuto, on 20 January 2012 - 03:04 PM, said:

Righto - your HTML looks solid, which is why I was curious about a full email... Particularly the "Content-Type" header.

One thing I've read about is that some code will use line-return characters in combination with, or instead of newline characters to concatenate email headers. Some email clients such as Gmail choke up if the headers weren't concatenated properly and will misinterpret the content type as a result.

I dug a little further, and as long as you're setting $mode to anything other than boolean FALSE, then we can disregard the Joomla controller being responsible for this problem as the Joomla JMail class never even touches the headers, directly. It inherits from the PHPMailer class. So if $mode is boolean TRUE, then your problem may well lie with PHPMailer.

PHPMailer is in and of itself a Google Code project, and while there are no issues listed specifically pertaining to your problem, one does mention consistent header anomalies.

There exists the possibility that your email client is gagging on improperly formatted headers. I might suggest attempting to open the email in several different clients. But again, examining the actual headers that are being dispatched is probably a solid debugging step at this point.

I'm going to check and see what mail client besides PHPMailer host gator is using. When I run a CRON job to execute a script that sends off the mail I receive it fine, but when a user registers I don't. Joomla! does provide other mail clients that I'll test.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1