function followchannel($channelid){ if ($_SESSION['user']->isAnon()) return array("ok"=>false, "error"=>"you have to login"); global $LANGALL; global $CONF; $channel = new Channel(); if (!isset($channelid)) return array("ok"=>false, "error"=>"no id"); $channel->setId($channelid); if ($channel->getAsktofollow()){ if ($_SESSION['user']->isAnon()) return array("ok"=>false, "error"=>"anon cant follow"); require_once('class/Message.php'); $message = new Message(); $message->setUserFrom($_SESSION['user']); $message->setUserTo($channel->getUser()); $__ufid = $channel->unconfirmed_follow(); $check=hash('sha512',"00`Θ^*' ♣ hk".chr(11)."1".$__ufid); if ($channel->getUser()->getLang()=='pt_br'){ $message->setSubject($LANGALL['pt_br']['channel_asktofollow_subject']); eval($LANGALL['pt_br']['channel_asktofollow_msg']); $msg = '#'.$channel->getName().'\n<br/>'.'@'.$_SESSION['user']->getNickname().'\n<br/>'.$body; if (isset($_GET['msg_followchannel'])) $msg.=$_GET['msg_followchannel']; $message->setMsg($msg); } else { $message->setSubject($LANGALL['en_us']['channel_asktofollow_subject']); eval($LANGALL['pt_br']['channel_asktofollow_msg']); $msg = '#'.$channel->getName().'\n<br/>'.'@'.$_SESSION['user']->getNickname().'\n<br/>'.$body; if (isset($_GET['msg_followchannel'])) $msg.=$_GET['msg_followchannel']; $message->setMsg($msg); } $result=$message->save(); if ($result=='ok') return array("ok"=>false, "error"=>"asked for permission", "msg"=>"asked for permission"); else return array("ok"=>false, "error"=>"error cant send message: ".$result, "msg"=>""); } else { if ($channel->follow()) return array("ok"=>true, "error"=>""); else return array("ok"=>false, "error"=>"cant follow"); } }
public function testSetGet() { $now = new \DateTime(); $testCase = ['id' => 123, 'level' => 2, 'subject' => 'TEST SUBJECT', 'message' => 'TEST MESSAGE', 'source' => 'TEST_SOURCE', 'dateCreated' => $now, 'dateCreatedString' => $now->format(\DateTime::ISO8601)]; $unit = new Message(); $unit->setId($testCase['id']); $this->assertEquals($testCase['id'], $unit->getId()); $unit->setLevel(0); $this->assertEquals(Message::LEVEL_DEFAULT, $unit->getLevel()); $unit->setLevel($testCase['level']); $this->assertEquals($testCase['level'], $unit->getLevel()); $unit->setSubject($testCase['subject']); $this->assertEquals($testCase['subject'], $unit->getSubject()); $unit->setMessage($testCase['message']); $this->assertEquals($testCase['message'], $unit->getMessage()); $unit->setSource(''); $this->assertNull($unit->getSource()); $unit->setSource($testCase['source']); $this->assertEquals($testCase['source'], $unit->getSource()); $unit->setDateCreated(null); $this->assertNull($unit->getDateCreatedString()); $unit->setDateCreated($testCase['dateCreated']); $this->assertEquals($testCase['dateCreated'], $unit->getDateCreated()); $unit->setDateCreatedString($testCase['dateCreatedString']); $this->assertEquals($testCase['dateCreatedString'], $unit->getDateCreatedString()); $this->assertEquals($testCase['id'], $unit->toArray()['id']); $this->assertTrue(is_array($unit->toArray())); }
function convertToMessage($msg) { $message = new Message(); $message->setId($msg['id']); $message->setDate($msg['sent_date']); $message->setFrom($msg['msg_from']); $message->setMessage($msg['message']); $message->setSubject($msg['subject']); return $message; }
function add_message() { global $CONF; $user = $_SESSION['user']; if ($user->getBanned()>0){ return array('ok'=>false, 'error'=>'banned '.$user->getBanned()); } if (isset($_SESSION['message_last_flood_time'])){ if ((time() - $_SESSION['message_last_flood_time']) < $CONF['message_time_to_wait_flood']){ $time_to_wait = $CONF['message_time_to_wait_flood'] - (time() - $_SESSION['message_last_flood_time']); return array('ok'=>false, 'error'=>'flood '.$time_to_wait); } } $_SESSION['message_last_flood_time']=time(); $user = $_SESSION['user']; $userto=new RegUser(); if (isset($_POST['user_to_id'])) $userto->setId($_POST['user_to_id']); elseif (isset($_POST['user_to_email'])) $userto->setEmail($_POST['user_to_email']); elseif (isset($_POST['user_to_nickname'])) $userto->setNickname($_POST['user_to_nickname']); else return array('ok'=>false, 'error'=>'undefined user to send'); $message = new Message(); $message->setUserFrom($user); $message->setUserTo($userto); $subject = strip_tags($_POST['subject']); if (strlen(str_replace(' ', '', $subject)) < $CONF['min_msg_chars']) return array('ok'=>false, 'error'=>'too short subject'); $message->setSubject($subject); $msg = unescape_ampersand($_POST['msg']); if (strlen(str_replace(' ', '', strip_tags($msg))) < $CONF['min_msg_chars']) return array('ok'=>false, 'error'=>'too short message'); $msg = strip_tags($msg, $CONF['permitted_tags_msg']); //$msg = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target=\"_BLANK\" href=\"\\0\">\\0</a>", $msg); //detectando URLs $msg = text_linkify($msg); $msg = str_replace(' ',' ',$msg); $message->setMsg($msg); $result = $message->save(); if ($result=='ok'){ return array('ok'=>true, 'error'=>''); } else return array('ok'=>false, 'error'=>'problems with this message: '.$result); }
public function testPut() { $message = new Message(); $message->setId(1); $message->setSubject('Un message'); $message->setContent('Bonjour. Une modification'); $message->setDatePost('2012-12-14 19:45:45'); $message->setIdSender(1); $message->setIdReceiver(3); $messageMapper = new MessageMapper(); $messageMapper->setId(1); $messageMapper->updateMessage($message); $this->assertEquals($message, $messageMapper->selectMessage()); }
<select ref="msgids" model="messages" appearance="placard"> <?php for ($i = 0; $i < 10 && $current_page * 10 + $i < $num_messages; $i++) { $message = new Message(); $current_message = $num_messages - ($current_page * 10 + $i); $message_uid = imap_uid($mbox, $current_message); $headers = imap_headerinfo($mbox, $current_message); $from = $headers->from[0]->personal ? $headers->from[0]->personal : $headers->from[0]->mailbox; $message->setFrom($from); $fromBlock = "<span class=\"subdued\">" . htmlspecialchars($message->getFrom()) . "</span>"; if ($headers->Unseen == 'U') { //Not read $fromBlock = "<strong>" . htmlspecialchars($message->getFrom()) . "</strong>"; } $message->setSubject($headers->subject); $date = strtotime($headers->date); $now = time(); $minutes_between = ($now - $date) / 60; if ($minutes_between < 60) { $display_date = round(($now - $date) / 60) . 'm ago'; } else { if ($minutes_between < 60 * 24) { $display_date = date('g:i a', $date); } else { $display_date = date('D g:i a', $date); } } ?> <item> <placard layout="template">
public function sendMessage() { if (isset($_POST['send-msg'])) { $to = $_POST['msgTo']; $msg = new Message(); $msg->setTo($to); $currentUser = wp_get_current_user(); $msg->setFrom($currentUser->ID); $msg->setSubject($_POST['subject']); $msg->setMessage($_POST['message']); $msg->send(); $this->redirect(admin_url('admin.php?page=vmp-msgs')); } }
public function notify($title) { global $redcap_version; $dark = "#800000"; //#1a74ba 1a74ba $light = "#FFE1E1"; //#ebf6f3 $border = "#800000"; //FF0000"; //#a6d1ed #3182b9 // Run notification $url = APP_PATH_WEBROOT_FULL . "redcap_v{$redcap_version}/" . "DataEntry/index.php?pid={$this->project_id}&page={$this->instrument}&id={$this->record}&event_id={$this->event_id}"; // Message (email html painfully copied from box.net notification email) $msg = RCView::table(array('cellpadding' => '0', 'cellspacing' => '0', 'border' => '0', 'style' => 'border:1px solid #bbb; font:normal 12px Arial;color:#666'), RCView::tr(array(), RCView::td(array('style' => 'padding:13px'), RCView::table(array('style' => 'font:normal 15px Arial'), RCView::tr(array(), RCView::td(array('style' => 'font-size:18px;color:#000;border-bottom:1px solid #bbb'), RCView::span(array('style' => 'color:black'), RCVieW::a(array('style' => 'color:black'), 'REDCap AutoNotification Alert')) . RCView::br())) . RCView::tr(array(), RCView::td(array('style' => 'padding:10px 0'), RCView::table(array('style' => 'font:normal 12px Arial;color:#666'), RCView::tr(array(), RCView::td(array('style' => 'text-align:right'), "Title") . RCView::td(array('style' => 'padding-left:10px;color:#000'), RCView::span(array('style' => 'color:black'), RCView::a(array('style' => 'color:black'), "<b>{$title}</b>")))) . RCView::tr(array(), RCView::td(array('style' => 'text-align:right'), "Project") . RCView::td(array('style' => 'padding-left:10px;color:#000'), RCView::span(array('style' => 'color:black'), RCView::a(array('style' => 'color:black'), REDCap::getProjectTitle())))) . ($this->redcap_event_name ? RCView::tr(array(), RCView::td(array('style' => 'text-align:right'), "Event") . RCView::td(array('style' => 'padding-left:10px;color:#000'), RCView::span(array('style' => 'color:black'), RCView::a(array('style' => 'color:black'), "{$this->redcap_event_name}")))) : '') . RCView::tr(array(), RCView::td(array('style' => 'text-align:right'), "Instrument") . RCView::td(array('style' => 'padding-left:10px;color:#000'), RCView::span(array('style' => 'color:black'), RCView::a(array('style' => 'color:black'), $this->instrument)))) . RCView::tr(array(), RCView::td(array('style' => 'text-align:right'), "Record") . RCView::td(array('style' => 'padding-left:10px;color:#000'), RCView::span(array('style' => 'color:black'), RCView::a(array('style' => 'color:black'), $this->record)))) . RCView::tr(array(), RCView::td(array('style' => 'text-align:right'), "Date/Time") . RCView::td(array('style' => 'padding-left:10px;color:#000'), RCView::span(array('style' => 'color:black'), RCView::a(array('style' => 'color:black'), date('Y-m-d H:i:s'))))) . RCView::tr(array(), RCView::td(array('style' => 'text-align:right'), "Message") . RCView::td(array('style' => 'padding-left:10px;color:#000'), RCView::span(array('style' => 'color:black'), RCView::a(array('style' => 'color:black'), $this->config['message']))))))) . RCView::tr(array(), RCView::td(array('style' => "border:1px solid {$border};background-color:{$light};padding:20px"), RCView::table(array('style' => 'font:normal 12px Arial', 'cellpadding' => '0', 'cellspacing' => '0'), RCView::tr(array('style' => 'vertical-align:middle'), RCView::td(array(), RCView::table(array('cellpadding' => '0', 'cellspacing' => '0'), RCView::tr(array(), RCView::td(array('style' => "border:1px solid #600000;background-color:{$dark};padding:8px;font:bold 12px Arial"), RCView::a(array('class' => 'hide', 'style' => 'color:#fff;white-space:nowrap;text-decoration:none', 'href' => $url), "View Record"))))) . RCView::td(array('style' => 'padding-left:15px'), "To view this record, visit this link:" . RCView::br() . RCView::a(array('style' => "color:{$dark}", 'href' => $url), $url)))))))))); $msg = "<HTML><head></head><body>" . $msg . "</body></html>"; // Determine number of emails to send // Prepare message $email = new Message(); $email->setTo($this->config['to']); $email->setFrom($this->config['from']); $email->setSubject($this->config['subject']); $email->setBody($msg); // Send Email if (!$email->send()) { error_log('Error sending mail: ' . $email->getSendError() . ' with ' . json_encode($email)); exit; } // error_log ('Email sent'); // Add Log Entry $data_values = "title,{$title}\nrecord,{$this->record}\nevent,{$this->redcap_event_name}"; REDCap::logEvent('AutoNotify Alert', $data_values); }
/** * function sendSimpleMessage * primary function for sending messages via array * * @return void * @author Sean Grove **/ public static function sendSimpleMessage($messageArray, $options = null) { // TODO: allow an email copy of the message to be sent out sfContext::getInstance()->getLogger()->log("message:" . print_r($messageArray, true)); sfContext::getInstance()->getLogger()->log("options:" . print_r($options, true)); if (!isset($messageArray["message_type"])) { $messageArray["message_type"] = 1; } sfContext::getInstance()->getLogger()->log('sending Message, owner sender'); $message = new Message(); $message->setSenderId($messageArray["from"]); sfContext::getInstance()->getLogger()->log('set from: ' . $messageArray["from"]); $message->setOwnerId($messageArray["owner"]); $message->setRecipientId($messageArray["to"]); $message->setParentId($messageArray["parent"]); $message->setSubject($messageArray["subject"]); $message->setBody($messageArray["text"]); $message->setHtmlBody('me'); $message->setFolder($messageArray["folder"]); $message->setMessageType($messageArray["message_type"]); $message->save(); if ($message->getMessageType() == 21) { EventUserPeer::addUser($message->getUuid(), $options["event_id"], $messageArray["from"], $options["points"], $options["comment"], $options["status"]); } if (isset($options["copyTo"]) && $options["copyTo"] == "sent") { sfContext::getInstance()->getLogger()->log('sending Message, owner recipient'); $message2 = array(); $message2["from"] = $messageArray["from"]; $message2["owner"] = $messageArray["from"]; $message2["to"] = $messageArray["to"]; $message2["parent"] = $messageArray["parent"]; $message2["subject"] = $messageArray["subject"]; $message2["text"] = $messageArray["text"]; $message2["folder"] = "sent"; self::sendSimpleMessage($message2); } if (!isset($options["notify"]) || $options["notify"] == true) { $sender = $message->getsfGuardUserRelatedBySenderId()->getProfile(); $recipient = $message->getsfGuardUserRelatedByRecipientId()->getProfile(); $text = '"' . $message->getSubject() . ' :: ' . $message->getBody() . '"'; $notification = 'New message from ' . $sender->getFullName() . ' on Cothink! '; $notification .= $text; $recipient->notify($notification); } sfContext::getInstance()->getLogger()->log('message sent'); }
public function testGetSetSubject() { $message = new Message(); $message->setSubject('Coucou'); $this->assertEquals('Coucou', $message->getSubject()); }
/** * Send an email using a Transactional email service * or native PHP as a fallback. * * @param array $attributes A list of attributes for sending * @return bool on success */ public static function send($attributes = array()) { /* |-------------------------------------------------------------------------- | Required attributes |-------------------------------------------------------------------------- | | We first need to ensure we have the minimum fields necessary to send | an email. | */ $required = array_intersect_key($attributes, array_flip(self::$required)); if (count($required) >= 3) { /* |-------------------------------------------------------------------------- | Load handler from config |-------------------------------------------------------------------------- | | We check the passed data for a mailer + key first, and then fall back | to the global Statamic config. | */ $email_handler = array_get($attributes, 'email_handler', Config::get('email_handler', null)); $email_handler_key = array_get($attributes, 'email_handler_key', Config::get('email_handler_key', null)); if (in_array($email_handler, self::$email_handlers) && $email_handler_key) { /* |-------------------------------------------------------------------------- | Initialize Stampie |-------------------------------------------------------------------------- | | Stampie provides numerous adapters for popular email handlers, such as | Mandrill, Postmark, and SendGrid. Each is written as an abstract | interface in an Adapter Pattern. | */ $mailer = self::initializeEmailHandler($email_handler, $email_handler_key); /* |-------------------------------------------------------------------------- | Initialize Message class |-------------------------------------------------------------------------- | | The message class is an implementation of the Stampie MessageInterface | */ $email = new Message($attributes['to']); /* |-------------------------------------------------------------------------- | Set email attributes |-------------------------------------------------------------------------- | | I hardly think this requires much explanation. | */ $email->setFrom($attributes['from']); $email->setSubject($attributes['subject']); if (isset($attributes['text'])) { $email->setText($attributes['text']); } if (isset($attributes['html'])) { $email->setHtml($attributes['html']); } if (isset($attributes['cc'])) { $email->setCc($attributes['cc']); } if (isset($attributes['bcc'])) { $email->setBcc($attributes['bcc']); } if (isset($attributes['headers'])) { $email->setHeaders($attributes['headers']); } $mailer->send($email); return true; } else { /* |-------------------------------------------------------------------------- | Native PHP Mail |-------------------------------------------------------------------------- | | We're utilizing the popular PHPMailer class to handle the messy | email headers and do-dads. Emailing from PHP in general isn't the best | idea known to man, so this is really a lackluster fallback. | */ try { $email = new PHPMailer(true); // SMTP if ($attributes['smtp'] = array_get($attributes, 'smtp', Config::get('smtp'))) { $email->isSMTP(); if ($smtp_host = array_get($attributes, 'smtp:host', false)) { $email->Host = $smtp_host; } if ($smtp_secure = array_get($attributes, 'smtp:secure', false)) { $email->SMTPSecure = $smtp_secure; } if ($smtp_port = array_get($attributes, 'smtp:port', false)) { $email->Port = $smtp_port; } if (array_get($attributes, 'smtp:auth', false) === TRUE) { $email->SMTPAuth = TRUE; } if ($smtp_username = array_get($attributes, 'smtp:username', false)) { $email->Username = $smtp_username; } if ($smtp_password = array_get($attributes, 'smtp:password', false)) { $email->Password = $smtp_password; } // SENDMAIL } elseif (array_get($attributes, 'sendmail', false)) { $email->isSendmail(); // PHP MAIL } else { $email->isMail(); } $email->CharSet = 'UTF-8'; $from_parts = self::explodeEmailString($attributes['from']); $email->setFrom($from_parts['email'], $from_parts['name']); $to = Helper::ensureArray($attributes['to']); foreach ($to as $to_addr) { $to_parts = self::explodeEmailString($to_addr); $email->addAddress($to_parts['email'], $to_parts['name']); } $email->Subject = $attributes['subject']; if (isset($attributes['html'])) { $email->msgHTML($attributes['html']); if (isset($attributes['text'])) { $email->AltBody = $attributes['text']; } } elseif (isset($attributes['text'])) { $email->msgHTML($attributes['text']); } if (isset($attributes['cc'])) { $cc = Helper::ensureArray($attributes['cc']); foreach ($cc as $cc_addr) { $cc_parts = self::explodeEmailString($cc_addr); $email->addCC($cc_parts['email'], $cc_parts['name']); } } if (isset($attributes['bcc'])) { $bcc = Helper::ensureArray($attributes['bcc']); foreach ($bcc as $bcc_addr) { $bcc_parts = self::explodeEmailString($bcc_addr); $email->addBCC($bcc_parts['email'], $bcc_parts['name']); } } $email->send(); } catch (phpmailerException $e) { echo $e->errorMessage(); //error messages from PHPMailer Log::error($e->errorMessage(), 'core', 'email'); } catch (Exception $e) { echo $e->getMessage(); Log::error($e->getMessage(), 'core', 'email'); } } } return false; }
/** * send: * * @param array|string $pmTo * - Who will receve the message, array('email', 'name') or * 'email' * @param string $psSubject * messagem subject * @param string $psBodyText * - message in plan text format * @param string $psBodyHtml * - message in html format * @param array|string $paFrom * - Who send the message, array('email', 'name') or 'email' * * @return Zend_Mail */ public function send($pmFrom, $psSubject, $pmBody, $pmTo = null) { $lsFromEmail = null; $lsFromName = null; $lsToEmail = null; $lsToName = null; $loMail = new Message(); $loMail->setEncoding($this->_aOptions['charset']); $loMail->setSender($this->_aOptions["fromEmail"], $this->_aOptions["fromName"]); $loMail->addReplyTo($this->_aOptions["replayToEmail"], $this->_aOptions["replayToName"]); $loMail->setSubject($psSubject); $loMail->setBody($this->setContainer($pmBody)); if (is_array($pmTo)) { if (isset($pmTo[0])) { $lsToEmail = $pmTo[0]; } if (isset($pmTo[1])) { $lsToName = $pmTo[1]; } } elseif (is_string($pmTo)) { $lsToEmail = $pmTo; } else { $lsToEmail = $this->_aOptions["fromEmail"]; $lsToName = $this->_aOptions["fromName"]; } $loMail->addTo($lsToEmail, $lsToName); if (is_array($pmFrom)) { if (isset($pmFrom[0])) { $lsFromEmail = $pmFrom[0]; } if (isset($pmFrom[1])) { $lsFromName = $pmFrom[1]; } } elseif (is_string($pmFrom)) { $lsFromEmail = $pmFrom; } else { $lsFromEmail = $this->_aOptions["fromEmail"]; $lsFromName = $this->_aOptions["fromName"]; } $loMail->setFrom($lsFromEmail, $lsFromName); if ($this->_aOptions["transporter"] == "SMTP") { $loOptionsSMTP = new Transport\SmtpOptions($this->getSMTPOptions()); $loTransport = new Transport\Smtp($loOptionsSMTP); $loTransport->send($loMail); } elseif ($this->_aOptions["transporter"] == "sendmail") { $loTransport = new Transport\Sendmail(); $loTransport->send($loMail); } }
/** * Send an email using a Transactional email service * or native PHP as a fallback. * * @param array $attributes A list of attributes for sending * @return bool on success */ public static function send($attributes = array()) { /* |-------------------------------------------------------------------------- | Required attributes |-------------------------------------------------------------------------- | | We first need to ensure we have the minimum fields necessary to send | an email. | */ $required = array_intersect_key($attributes, array_flip(self::$required)); if (count($required) >= 3) { /* |-------------------------------------------------------------------------- | Load handler from config |-------------------------------------------------------------------------- | | We check the passed data for a mailer + key first, and then fall back | to the global Statamic config. | */ $email_handler = array_get($attributes, 'email_handler', Config::get('email_handler', null)); $email_handler_key = array_get($attributes, 'email_handler_key', Config::get('email_handler_key', null)); if (in_array($email_handler, self::$email_handlers) && $email_handler_key) { /* |-------------------------------------------------------------------------- | Initialize Stampie |-------------------------------------------------------------------------- | | Stampie provides numerous adapters for popular email handlers, such as | Mandrill, Postmark, and SendGrid. Each is written as an abstract | interface in an Adapter Pattern. | */ $mailer = self::initializeEmailHandler($email_handler, $email_handler_key); /* |-------------------------------------------------------------------------- | Initialize Message class |-------------------------------------------------------------------------- | | The message class is an implementation of the Stampie MessageInterface | */ $email = new Message($attributes['to']); /* |-------------------------------------------------------------------------- | Set email attributes |-------------------------------------------------------------------------- | | I hardly think this requires much explanation. | */ $email->setFrom($attributes['from']); $email->setSubject($attributes['subject']); if (isset($attributes['text'])) { $email->setText($attributes['text']); } if (isset($attributes['html'])) { $email->setHtml($attributes['html']); } if (isset($attributes['cc'])) { $email->setCc($attributes['cc']); } if (isset($attributes['bcc'])) { $email->setBcc($attributes['bcc']); } if (isset($attributes['headers'])) { $email->setHeaders($attributes['headers']); } $mailer->send($email); return true; } else { /* |-------------------------------------------------------------------------- | Native PHP Mail |-------------------------------------------------------------------------- | | We're utilizing the popular PHPMailer class to handle the messy | email headers and do-dads. Emailing from PHP in general isn't the best | idea known to man, so this is really a lackluster fallback. | */ $email = new PHPMailer(true); $email->IsMAIL(); $email->CharSet = 'UTF-8'; $email->AddAddress($attributes['to']); $email->From = $attributes['from']; $email->FromName = $attributes['from']; $email->Subject = $attributes['subject']; if (isset($attributes['text'])) { $email->AltBody = $attributes['text']; } if (isset($attributes['html'])) { $email->Body = $attributes['html']; $email->IsHTML(true); } if (isset($attributes['cc'])) { $email->AddCC($attributes['cc']); } if (isset($attributes['bcc'])) { $email->AddBCC($attributes['bcc']); } if ($email->Send()) { return true; } } } return false; }
public function mailInvoiceContract($sender,$reciver,$subject,$body,$fileData,$title){ try { $image_data=$fileData; $image_content_id=$title; $message = new Message(); $message->setSender($sender); $message->addTo($reciver); $message->setSubject($subject); $message->setTextBody($body); $message->addAttachment($title.'.docx', $image_data, $image_content_id); $message->send(); } catch (InvalidArgumentException $e) { echo $e->getMessage(); } }
/** * Compose a new message, and process new message submissions * @parm int $reply message ID this message is in reply to [optional] only used to pre-populate subject and recipient * @return void */ private function newMessage($reply = 0) { $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'messages/create.tpl.php', 'footer.tpl.php'); require_once FRAMEWORK_PATH . 'models/relationships.php'; $relationships = new Relationships($this->registry); if (isset($_POST) && count($_POST) > 0) { $network = $relationships->getNetwork($this->registry->getObject('authenticate')->getUser()->getUserID()); $recipient = intval($_POST['recipient']); if (in_array($recipient, $network)) { // this additional check may not be something we require for private messages? require_once FRAMEWORK_PATH . 'models/message.php'; $message = new Message($this->registry, 0); $message->setSender($this->registry->getObject('authenticate')->getUser()->getUserID()); $message->setRecipient($recipient); $message->setSubject($this->registry->getObject('db')->sanitizeData($_POST['subject'])); $message->setMessage($this->registry->getObject('db')->sanitizeData($_POST['message'])); $message->save(); // email notification to the recipient perhaps?? // confirm, and redirect $url = $this->registry->getObject('url')->buildURL(array('messages'), '', false); $this->registry->redirectUser($url, 'Message sent', 'The message has been sent'); } else { $this->registry->errorPage('Invalid recipient', 'Sorry, you can only send messages to your recipients'); } } else { $cache = $relationships->getByUser($this->registry->getObject('authenticate')->getUser()->getUserID()); $this->registry->getObject('template')->getPage()->addTag('recipients', array('SQL', $cache)); if ($reply > 0) { require_once FRAMEWORK_PATH . 'models/message.php'; $message = new Message($this->registry, $reply); if ($message->getRecipient() == $this->registry->getObject('authenticate')->getUser()->getUserID()) { $this->registry->getObject('template')->getPage()->addAdditionalParsingData('recipients', 'ID', $message->getSender(), 'opt', "selected='selected'"); $this->registry->getObject('template')->getPage()->addTag('subject', 'Re: ' . $message->getSubject()); } else { $this->registry->getObject('template')->getPage()->addTag('subject', ''); } } else { $this->registry->getObject('template')->getPage()->addTag('subject', ''); } } }
$path= $bucket_id.'excel/'; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save($path."ALLIANCE TS REPORT.xls"); $drop_query="DROP TABLE $temp_table_name "; mysqli_query($con,$drop_query); //SENDING MAIL OPTIONS $imagefilename='ALLIANCE TIME SHEET IMAGE REPORT '.date("d-m-Y").'.pdf'; $reportfilename='ALLIANCE TIME SHEET REPORT '.date("d-m-Y").'.pdf'; $excelfilename='ALLIANCE TIME SHEET REPORT '.date("d-m-Y").'.xls'; $imageheader='ALLIANCE TIME SHEET IMAGE REPORT '.date("d-m-Y"); $reportheader='ALLIANCE TIME SHEET REPORT '.date("d-m-Y"); $message1 = new Message(); $message1->setSender($admin); $message1->addTo($admin); $message1->addCc($sadmin); $message1->setSubject($mail_subject); $message1->setHtmlBody($sub); $mpdf=new mPDF('utf-8',array(300,200)); $mpdf->debug=true; $mpdf->SetHTMLHeader('<h3><div style="text-align: center; font-weight: bold;margin-bottom: 2cm;">'.$reportheader.'</div></h3>', 'O', true); $mpdf->SetHTMLFooter('<div style="text-align: center;">{PAGENO}</div>'); $mpdf->WriteHTML($message); $reportpdf=$mpdf->Output('ALLIANCE TIME SHEET REPORT ' .date("d-m-Y"). '.pdf','S'); $message1->addAttachment($reportfilename,$reportpdf); $mpdf=new mPDF('utf-8','A4'); $mpdf->debug=true; $mpdf->SetHTMLHeader('<h3><div style="text-align: center; font-weight: bold;margin-bottom: 2cm;">'.$imageheader.'</div></h3>', 'O', true); $mpdf->SetHTMLFooter('<div style="text-align: center;">{PAGENO}</div>'); $mpdf->WriteHTML($html); $imagepdf=$mpdf->Output('ALLIANCE TIME SHEET IMAGE REPORT '.date("d-m-Y").'.pdf','S'); $message1->addAttachment($imagefilename,$imagepdf);
if ($check==$_GET['c']){ $ufc_=Channel::confirmFollow($_GET['b'],$_GET['a']=='accept'); if (count($ufc_)>0){ $userto=new RegUser(); $userto->setId($ufc_['userid']);$userto->load(); $channel=new Channel(); $channel->setId($ufc_['channelid']); $message = new Message(); $message->setUserFrom($_SESSION['user']); $message->setUserTo($userto); if ($_GET['a']=='accept'){ $msg=$LANG['channel_confirmfollow_accepted']; if ($userto->getLang()=='pt_br'){ $message->setSubject($LANGALL['pt_br']['channel_asktofollow_subject']); $message->setMsg('#'.$channel->getName().'\n<br/>'.$LANGALL['pt_br']['channel_confirmfollow_accepted']); } else { $message->setSubject($LANGALL['en_us']['channel_asktofollow_subject']); $message->setMsg('#'.$channel->getName().'\n<br/>'.$LANGALL['en_us']['channel_confirmfollow_accepted']); } } else { $msg=$LANG['channel_confirmfollow_rejected']; if ($userto->getLang()=='pt_br'){ $message->setSubject($LANGALL['pt_br']['channel_asktofollow_subject']); $message->setMsg('#'.$channel->getName().'\n<br/>'.$LANGALL['pt_br']['channel_confirmfollow_rejected']); } else { $message->setSubject($LANGALL['en_us']['channel_asktofollow_subject']); $message->setMsg('#'.$channel->getName().'\n<br/>'.$LANGALL['en_us']['channel_confirmfollow_rejected']); } }
/** * @param $userid * @param $headers * @param $table_csv * @param array $fields * @param $parent_chkd_flds * @param $export_file_name * @param $debug * @param null $comment * @param array $to */ public static function do_sendit($userid, $headers, $table_csv, $fields = array(), $parent_chkd_flds, $export_file_name, $comment = null, $to = array(), $debug) { global $project_id, $user_rights, $app_title, $lang, $redcap_version; // we could use the global $userid, but we need control of it for setting the user as [CRON], so this is passed in args. $return_val = false; $export_type = 0; // this puts all files generated here in the Data Export category in the File Repository $today = date("Y-m-d_Hi"); //get today for filename $projTitleShort = substr(str_replace(" ", "", ucwords(preg_replace("/[^a-zA-Z0-9 ]/", "", html_entity_decode($app_title, ENT_QUOTES)))), 0, 20); // shortened project title for filename $originalFilename = $projTitleShort . "_" . $export_file_name . "_DATA_" . $today . ".csv"; // name the file for storage $today = date("Y-m-d-H-i-s"); // get today for comment, subsequent processing as needed $docs_comment_WH = $export_type ? "Data export file created by $userid on $today" : fix_case($export_file_name) . " file created by $userid on $today. $comment"; // unused, but I keep it around just in case /** * setup vars for value export logging */ $chkd_fields = implode(',', $fields); /** * turn on/off exporting per user rights */ if (($user_rights['data_export_tool'] || $userid == '[CRON]') && !$debug) { $table_csv = addBOMtoUTF8($headers . $table_csv); /** * Store the file in the file system and log the activity, handle if error */ if (!DataExport::storeExportFile($originalFilename, $table_csv, true)) { log_event("", "redcap_data", "data_export", "", str_replace("'", "", $chkd_fields) . (($parent_chkd_flds == "") ? "" : ", " . str_replace("'", "", $parent_chkd_flds)), "Data Export Failed"); } else { log_event("", "redcap_data", "data_export", "", str_replace("'", "", $chkd_fields) . (($parent_chkd_flds == "") ? "" : ", " . str_replace("'", "", $parent_chkd_flds)), "Export data for SendIt"); /** * email file link and download password in two separate emails via REDCap SendIt */ $file_info_sql = db_query("SELECT docs_id, docs_size, docs_type FROM redcap_docs WHERE project_id = $project_id ORDER BY docs_id DESC LIMIT 1"); // get required info about the file we just created if ($file_info_sql) { $docs_id = db_result($file_info_sql, 0, 'docs_id'); $docs_size = db_result($file_info_sql, 0, 'docs_size'); $docs_type = db_result($file_info_sql, 0, 'docs_type'); } $yourName = 'PRIORITIZE REDCap'; $expireDays = 3; // set the SendIt to expire in this many days /** * $file_location: * 1 = ephemeral, will be deleted on $expireDate * 2 = export file, visible only to rights in file repository */ $file_location = 2; $send = 1; // always send download confirmation $expireDate = date('Y-m-d H:i:s', strtotime("+$expireDays days")); $expireYear = substr($expireDate, 0, 4); $expireMonth = substr($expireDate, 5, 2); $expireDay = substr($expireDate, 8, 2); $expireHour = substr($expireDate, 11, 2); $expireMin = substr($expireDate, 14, 2); // Add entry to sendit_docs table $query = "INSERT INTO redcap_sendit_docs (doc_name, doc_orig_name, doc_type, doc_size, send_confirmation, expire_date, username, location, docs_id, date_added) VALUES ('$originalFilename', '" . prep($originalFilename) . "', '$docs_type', '$docs_size', $send, '$expireDate', '" . prep($userid) . "', $file_location, $docs_id, '" . NOW . "')"; db_query($query); $newId = db_insert_id(); $logDescrip = "Send file from file repository (Send-It)"; log_event($query, "redcap_sendit_docs", "MANAGE", $newId, "document_id = $newId", $logDescrip); // Set email subject $subject = "[PRIORITIZE] " . $comment; $subject = html_entity_decode($subject, ENT_QUOTES); // Set email From address $from = array('Ken Bergquist' => '*****@*****.**'); // Begin set up of email to send to recipients $email = new Message(); foreach ($from as $name => $address) { $email->setFrom($address); $email->setFromName($name); } $email->setSubject($subject); // Loop through each recipient and send email foreach ($to as $name => $address) { // If a non-blank email address if (trim($address) != '') { // create key for unique url $key = strtoupper(substr(uniqid(md5(mt_rand())), 0, 25)); // create password $pwd = generateRandomHash(8, false, true); $query = "INSERT INTO redcap_sendit_recipients (email_address, sent_confirmation, download_date, download_count, document_id, guid, pwd) VALUES ('$address', 0, NULL, 0, $newId, '$key', '" . md5($pwd) . "')"; $q = db_query($query); // Download URL $url = APP_PATH_WEBROOT_FULL . 'redcap_v' . $redcap_version . '/SendIt/download.php?' . $key; // Message from sender $note = "$comment for $today"; // Get YMD timestamp of the file's expiration time $expireTimestamp = date('Y-m-d H:i:s', mktime($expireHour, $expireMin, 0, $expireMonth, $expireDay, $expireYear)); // Email body $body = "<html><body style=\"font-family:Arial;font-size:10pt;\"> $yourName {$lang['sendit_51']} \"$originalFilename\" {$lang['sendit_52']} " . date('l', mktime($expireHour, $expireMin, 0, $expireMonth, $expireDay, $expireYear)) . ", " . DateTimeRC::format_ts_from_ymd($expireTimestamp) . "{$lang['period']} {$lang['sendit_53']}<br><br> {$lang['sendit_54']}<br> <a href=\"$url\">$url</a><br><br> $note <br>-----------------------------------------------<br> {$lang['sendit_55']} " . CONSORTIUM_WEBSITE_DOMAIN . ". </body></html>"; // Construct email and send $email->setTo($address); $email->setToName($name); $email->setBody($body); if ($email->send()) { // Now send follow-up email containing password $bodypass = "******"font-family:Arial;font-size:10pt;\"> {$lang['sendit_50']}<br><br> $pwd<br><br> </body></html>"; $email->setSubject("Re: $subject"); $email->setBody($bodypass); sleep(2); // Hold for a second so that second email somehow doesn't reach the user first $email->send(); } else { error_log("ERROR: pid=$project_id: Email to $name <$address> NOT SENT"); } } } } unset($table_csv); } }
/** * Sends a message in an extremly simple but less extensive way * * @param mixed from address. Either string or array, where the key is the address and the value the name * @param mixed Either string or array, where the keys are the addresses and the values the namen * @param string subject * @param string body */ public function sendSimple($from, $to, $subject, $body) { $message = new Message(); $message->setSubject($subject)->setFrom($from)->setTo($to)->setBody($body, 'text/html'); if ($this->debug === true) { return $this->debug($message); } if (isset($this->overrideRecipientEmailAddress)) { $message->setTo($this->overrideRecipientEmailAddress); $message->setCc(array()); $message->setBcc(array()); } $result = $this->getMailer()->send($message->message); Yii::trace($this->logger->dump()); return $result; }
$to = array( 'Ken Bergquist' => '*****@*****.**', 'Lasheaka McClellan' => '*****@*****.**', 'Tyre Johnson' => '*****@*****.**', 'Dona-Marie Mintz' => '*****@*****.**', 'Nicholas Slater' => '*****@*****.**' ); //$to = array('Ken Bergquist' => '*****@*****.**'); $from = array('Ken Bergquist' => '*****@*****.**'); $subject = "HCV-TARGET 2 Site Source Upload Notification"; $email = new Message (); foreach ($from as $name => $address) { $email->setFrom($address); $email->setFromName($name); } $email->setSubject($subject); $email->setBody($html); foreach ($to as $name => $address) { $email->setTo($address); $email->setToName($name); if (!$debug) { if (!$email->send()) { error_log("ERROR: Failed to send Site Source Upload digest"); } } } d($email); } else { error_log("NOTICE: No site source uploads were available to be digested"); } }
/** * function generateReplyMessage * makes a reply message for this message object * * @return Message * @author Sean Grove **/ public function generateReplyMessage() { $message = new Message(); $message->setRecipientId($this->getSenderId()); $message->setSenderId(sfContext::getInstance()->getUser()->getProfile()->getUserId()); $message->setParentId($this->getUuid()); $message->setSubject('re: ' . $this->getSubject()); $message->setBody($this->formatMessageReply()); sfContext::getInstance()->getLogger()->info('Set Msg parent id to :[' . $message->getParentId() . '], should be [' . $this->getUuid() . ']'); if ($message->getRecipientId() == sfContext::getInstance()->getUser()->getProfile()->getUserId()) { $message->setRecipientId($this->getRecipientId()); } return $message; }