public function sendTo($recipient) { if (is_array($recipient)) { if (isset($recipient['login'])) { if (!(isset($recipient['email']) && isset($recipient['name']) && isset($recipient['surname']) && isset($recipient['user_type']))) { $recipient = $recipient['login']; } else { $defined = 1; } } else { throw new EfrontNotificationException(_UNKNOWNRECIPIENT, EfrontNotificationException::NORECIPIENTLOGIN_DEFINED); } } if (!$defined) { $recipient = eF_getTableData("users", "*", "login = '******'"); if (!empty($recipient)) { $recipient = $recipient[0]; } else { throw new EfrontNotificationException(_UNKNOWNRECIPIENT, EfrontNotificationException::NORECIPIENTLOGIN_DEFINED); } } // create the array of substitutions for this particular user and replace them in the subject/message texts $hostname = G_SERVERNAME; if ($hostname[strlen($hostname) - 1] == "/") { $hostname = substr($hostname, 0, strlen($hostname) - 1); } $language = eF_getTableData("languages", "translation", "name = '" . $recipient['languages_NAME'] . "'"); if (!empty($language)) { $language = $language[0]['translation']; } $template_formulations = array("users_name" => $recipient['name'], "users_surname" => $recipient['surname'], "users_login" => $recipient['login'], "users_email" => $recipient['email'], "users_comments" => $recipient['comments'], "users_language" => $language, "date" => formatTimestamp(time()), "date_time" => formatTimestamp(time(), 'time'), "timestamp" => time(), "user_type" => $recipient['user_type'], "host_name" => $hostname, "site_name" => $GLOBALS['configuration']['site_name'], "site_motto" => $GLOBALS['configuration']['site_motto']); $header = array('From' => $GLOBALS['configuration']['system_email'], 'To' => $recipient['email'], 'Subject' => eF_formulateTemplateMessage($this->notification['subject'], $template_formulations), 'Content-Transfer-Encoding' => '7bit', 'Date' => date("r")); if ($this->notification['html_message'] == 1) { $header['Content-type'] = 'text/html;charset="UTF-8"'; // if content-type is text/html, the message cannot be received by mail clients for Registration content } else { $header['Content-type'] = 'text/plain;charset="UTF-8"'; } $smtp = Mail::factory('smtp', array('auth' => $GLOBALS['configuration']['smtp_auth'] ? true : false, 'host' => $GLOBALS['configuration']['smtp_host'], 'password' => $GLOBALS['configuration']['smtp_pass'], 'port' => $GLOBALS['configuration']['smtp_port'], 'username' => $GLOBALS['configuration']['smtp_user'], 'timeout' => $GLOBALS['configuration']['smtp_timeout'])); // force url change for html messages $message = eF_getCorrectLanguageMessage($this->notification['message'], $recipient['languages_NAME']); // Local paths names should become urls if ($this->notification['html_message'] == 1) { $message = str_replace('="content', '="###host_name###/content', $message); /* * //Commented-out Feb 2013 (periklis) because it's no longer needed (probably) if ($configuration['math_images']) { $message = "<html><body><script type = \"text/javascript\" src = \"###host_name###/js/ASCIIMath2Tex.js\"> </script>".$message."</body></html>"; } else { $message = "<html><body><script type = \"text/javascript\" src = \"###host_name###/js/ASCIIMathML.js\"> </script>".$message."</body></html>"; } */ } else { $message = str_replace("<br />", "\r\n", $message); $message = str_replace("<br>", "\r\n", $message); $message = str_replace("<p>", "\r\n", $message); $message = str_replace("</p>", "\r\n", $message); $message = str_replace("&", "&", $message); $message = strip_tags($message); } $message = eF_formulateTemplateMessage($message, $template_formulations); $message = eF_replaceMD5($message); if ($GLOBALS['configuration']['notifications_send_mode'] == 0) { //email only if (!empty($recipient['email'])) { $result = $smtp->send($recipient['email'], $header, $message); } } else { if ($GLOBALS['configuration']['notifications_send_mode'] == 1) { //pm only $pm = new eF_PersonalMessage($recipient['login'], $recipient['login'], $header['Subject'], $message); $result = $pm->send(); } else { if ($GLOBALS['configuration']['notifications_send_mode'] == 2) { //email and pm $pm = new eF_PersonalMessage($recipient['login'], $recipient['login'], $header['Subject'], $message); $pm->send(); if (!empty($recipient['email'])) { $result = $smtp->send($recipient['email'], $header, $message); } } } } if (PEAR::isError($result)) { $admin = EfrontSystem::getAdministrator(); eF_mail($GLOBALS['configuration']['system_email'], $admin->user['email'], _AUTOMATEDEMAILSENTFROM . $admin->user['email'], $result->getMessage()); throw new EfrontNotificationException($result->getMessage(), EfrontNotificationException::GENERAL_ERROR); } if ($result === true) { // put into sent_notifications table eF_insertTableData("sent_notifications", array("timestamp" => time(), "recipient" => $recipient['email'] . " (" . $recipient['name'] . " " . $recipient['surname'] . ")", "subject" => $header['Subject'], "body" => $message, "html_message" => $this->notification['html_message'])); return true; } else { return false; } }
function eF_replaceMD5($message) { $pos = strpos($message, "###md5("); //echo "*****".$pos."****<BR>"; if ($pos) { $remaining_msg = substr($message, $pos + 7); //echo $remaining_msg."<BR>"; $pos2 = strpos($remaining_msg, ")###"); //echo "*****".$pos2."****<BR>"; if ($pos2) { $message = substr($message, 0, $pos) . md5(substr($message, $pos + 7, $pos2) . G_MD5KEY) . eF_replaceMD5(substr($message, $pos + 7 + $pos2 + 4)); } } return $message; }