JEvents: e-mail function improved

Submitted by Jochus on Tue, 20/11/2007 - 22:28 | Posted in: Website


Op Jochus.be maakte ik vroeger gebruik van JEvents als agenda (in combinatie met Joomla!). Zo kan ik gemakkelijk overal zien wat ik komende dagen/maanden/... gepland heb. Op de dag van vandaag gebruik ik de GUI van Google Agenda itself. De Google Agenda is trouwens perfect synchroniseerbaar met elk device (computer, smartphone, ...).

Bij het publishen van een nieuw "event" bij JEvents, wordt er een mail verstuurd. Deze mail kan echter maar naar één gebruiker gestuurd worden, de admin. Bovendien was de opmaak van de mail alles behalve deftig. Daarom heb ik besloten de code te herschrijven. Opmerkingen zijn altijd welkom, ik heb niet alles aangepast om de Joomla! standaarden wat te behouden, but feel free to copy :-).

Originele code

function sendAdminMail( $adminName, $adminEmail, $subject='', $title='', $content='', $author='', $live_site, $modifylink ) {
 
	if (!$adminEmail) return;
 
	$htmlmail = true;
	$lf = ($htmlmail === true) ? '<br />' : '\r\n';
 
	$content  = 'Title: ' . $title . $lf.$lf . $content;
	$content .= $lf.$lf. sprintf( _CAL_LANG_MAIL_TO_ADMIN, $live_site, $author );
	$content .= $lf . 'Edit : ' . $modifylink;
 
	// mail function
	//mosMail( $mosConfig_mailfrom, $mosConfig_fromname, $email, $subject, $msg );
	mosMail( $adminEmail, $adminName, $adminEmail, $subject, $content, $htmlmail );
}

Aangepaste code

function sendAdminMail( $adminName, $adminEmail, $subject='', $title='', $content='', $author='', $live_site, $modifylink, $publishtime, $location, $catid, $db ) {
 
	// SETUP MAIL
	if (!$adminEmail) {
		return;
	}
	$htmlmail = true;
	$lf = ($htmlmail === true) ? '<br/>' : '\r\n';
 
	// CHECK FOR SQL INJECTION
	$catid_checked = do_sql_injection($catid);
 
	// PREPARING DATA
	$query = "SELECT title FROM mos_categories WHERE id = '$catid_checked'";
	$db->setQuery($query);
	$resultset = $db->query();
	$data = mysql_fetch_array($resultset);
 
	// SET CONTENT
	$content  = '<b>Title:</b> ' . $title;
	$content .= $lf . '<b>From: </b>' . $author ;
	$content .= $lf . '<b>Date: </b>' . $publishtime;
	$content .= $lf . '<b>Location : </b>' . $location;
	$content .= $lf . '<b>Category : </b>' . $data['title'];
	$content .= $lf . '<b>Edit : </b>' . $modifylink;
 
	// SET EMAIL ACCOUNTS
	$listEmails = array();
	$listEmails[0] = $adminEmail;
	$listEmails[1] = "<a href="mailto:some@mail.com">some@mail.com</a>";
 
	$subject = "[Jochus.be] New submission: " . $title;
 
 
	// JOOMLA MAIL FUNCTION
	mosMail( $adminEmail, $adminName, $listEmails, $subject, $content, $htmlmail );
}

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.