/** * Using an email template, this will queue up an email into the email queue to be sent out. * @param string $strTemplateName the name of the template to use * @param string $strSubject the subject of the email * @param string $strFrom who the email is sent from * @param string $strTo who the email shout be sent to * @param string $strTokenArray the replacement token array * @param boolean $blnHighPriorityFlag whether or not this is a high priority message (to be sent before all other queued messages) * @return void */ public static function SendEmailUsingTemplate($strTemplateName, $strSubject, $strFrom, $strTo, $strTokenArray, $blnHighPriorityFlag = false) { $strContent = file_get_contents(__INCLUDES__ . '/email_templates/' . $strTemplateName . '.txt'); foreach ($strTokenArray as $strKey => $strValue) { $strContent = str_replace('%' . $strKey . '%', $strValue, $strContent); } $objEmail = new EmailQueue(); $objEmail->ToAddress = $strTo; $objEmail->FromAddress = $strFrom; $objEmail->Subject = $strSubject; $objEmail->Body = $strContent; $objEmail->HighPriorityFlag = $blnHighPriorityFlag; $objEmail->Save(); }
/** * For subscribers of this message topic, send out an alert to them given this new message * @return void */ public function SendAlerts() { switch ($this->TopicLink->TopicLinkTypeId) { case TopicLinkType::Forum: $strLink = sprintf('http://www.qcodo.com/forums/forum.php/%s/%s/lastpage', $this->TopicLink->ForumId, $this->TopicId); break; case TopicLinkType::Issue: $strLink = sprintf('http://www.qcodo.com/issues/view.php/%s/lastpage', $this->TopicLink->IssueId); break; case TopicLinkType::WikiItem: $strLink = sprintf('http://www.qcodo.com%s?lastpage', $this->TopicLink->WikiItem->UrlPath); break; case TopicLinkType::Package: $strLink = sprintf('http://www.qcodo.com/qpm/package.php/%s/lastpage', $this->TopicLink->Package->Token); break; default: throw new Exception('Unhandled TopicLinkType: ' . $this->TopicLink->TopicLinkTypeId); } $strDisplayName = $this->Person ? $this->Person->DisplayName : 'Qcodo System Message'; $strBody = "QCODO MESSAGE POSTED\r\n"; $strBody .= sprintf("Topic: %s\r\n", $this->Topic->Name); $strBody .= sprintf("Posted By: %s\r\n", $strDisplayName); $strBody .= sprintf("Posted On: %s\r\n", $this->PostDate->__toString('DDD MMM D YYYY, h:mm zz')); $strBody .= sprintf("(to view this topic in its entirety, please go to %s)\r\n\r\n\r\n", $strLink); $strBody .= trim($this->Message); $strBody .= "\r\n\r\n------------------------------------------------------\r\nYou are receiving this message because you have opted-in for email notifications on this topic. "; $strBody .= "If you wish to no longer be notified for this topic, please go to "; $strBody .= $strLink; $strBody .= ' and click on "Email Notification". If the link does not show up, you will need first "Log In".'; $strHtml = '<style type="text/css">'; $strHtml .= 'pre { background-color: #ddddff; padding: 10px; margin-left: 20px; font-family: "Lucida Console", "Courier New", "Courier", "monospaced"; font-size: 11px; line-height: 13px; overflow: auto; }'; $strHtml .= '</style>'; $strHtml .= sprintf('<span style="font: 12px %s;">', QFontFamily::Verdana); $strHtml .= '<span style="font-size: 14px;"><strong><a href="http://www.qcodo.com/">Qcodo</a> Message Posted</strong></span><br/>'; $strHtml .= sprintf('<strong>Topic: </strong>%s<br/>', $this->Topic->Name); $strHtml .= sprintf('<strong>Posted By: </strong>%s<br/>', $strDisplayName); $strHtml .= sprintf('<strong>Posted On: </strong>%s<br/>', $this->PostDate->__toString('DDD MMM D YYYY, h:mm zz')); $strHtml .= sprintf('(to view this post in its entirety, please go to <a href="%s">%s</a>)<br/><br/><br/>', $strLink, $strLink); $strHtml .= $this->CompiledHtml; $strHtml .= '<br/><br/><hr/><br/><span style="font-size: 10px;">You are receiving this message because you have opted-in for email notifications on this forum topic. '; $strHtml .= 'If you wish to no longer be notified for this topic, please go to '; $strHtml .= sprintf('<a href="%s">%s</a>', $strLink, $strLink); $strHtml .= ' and click on "<strong>Email Notification</strong>". If the link does not show up, you will need first "<strong>Log In</strong>".'; $strHtml .= '</span></span>'; $strSubject = '[Qcodo] Re: ' . $this->Topic->Name; foreach ($this->Topic->GetPersonAsEmailArray() as $objEmailPerson) { if ($objEmailPerson->Id != $this->PersonId) { $objEmailQueue = new EmailQueue(); $objEmailQueue->ToAddress = sprintf('%s %s <%s>', $objEmailPerson->FirstName, $objEmailPerson->LastName, $objEmailPerson->Email); $objEmailQueue->FromAddress = QCODO_EMAILER; $objEmailQueue->Subject = $strSubject; $objEmailQueue->Body = $strBody; $objEmailQueue->Html = $strHtml; $objEmailQueue->Save(); } } }