/**
  * Send an email notification to all super users.
  *
  * @param $subject
  * @param $message
  */
 protected function sendEmailNotification($subject, $message)
 {
     $superUsers = UsersManagerApi::getInstance()->getUsersHavingSuperUserAccess();
     foreach ($superUsers as $superUser) {
         $mail = new Mail();
         $mail->setDefaultFromPiwik();
         $mail->addTo($superUser['email']);
         $mail->setSubject($subject);
         $mail->setBodyText($message);
         $mail->send();
     }
 }
Example #2
0
 public static function sendNotificationToAdmin($args)
 {
     list($idsite, $idvisitor, $message) = $args;
     $visitorInfo = ChatPersonnalInformation::get($idvisitor);
     $subject = "New message on " . ChatSite::getSiteName($idsite);
     $mail = new Mail();
     $mail->setFrom(Config::getInstance()->General['noreply_email_address'], "Piwik Chat");
     $mail->setSubject($subject);
     $mail->setBodyHtml("Name : " . $visitorInfo['name'] . "<br />\n        Email : " . $visitorInfo['email'] . "<br />\n        Phone : " . $visitorInfo['phone'] . "<br />\n        Comments : " . $visitorInfo['comments'] . "<br />\n        <br /><br />\n        Message:<br />{$message}");
     foreach (ChatCommon::getUsersBySite($idsite) as $user) {
         if (empty($user['email'])) {
             continue;
         }
         if (ChatPiwikUser::isStaffOnline($user['login'])) {
             continue;
         }
         $mail->addTo($user['email']);
         try {
             $mail->send();
         } catch (Exception $e) {
             throw new Exception("An error occured while sending '{$subject}' " . " to " . implode(', ', $mail->getRecipients()) . ". Error was '" . $e->getMessage() . "'");
         }
         $mail->clearRecipients();
     }
 }
Example #3
0
 private function sendMail($subject, $body)
 {
     $feedbackEmailAddress = Config::getInstance()->General['feedback_email_address'];
     $subject = '[ Feedback Feature - Piwik ] ' . $subject;
     $body = Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Version::VERSION . "\n" . 'IP: ' . IP::getIpFromHeader() . "\n" . 'URL: ' . Url::getReferrer() . "\n";
     $mail = new Mail();
     $mail->setFrom(Piwik::getCurrentUserEmail());
     $mail->addTo($feedbackEmailAddress, 'Piwik Team');
     $mail->setSubject($subject);
     $mail->setBodyText($body);
     @$mail->send();
 }
Example #4
0
 /**
  * @return void
  */
 private function initSmtpTransport()
 {
     $mailConfig = Config::getInstance()->mail;
     if (empty($mailConfig['host']) || $mailConfig['transport'] != 'smtp') {
         return;
     }
     $smtpConfig = array();
     if (!empty($mailConfig['type'])) {
         $smtpConfig['auth'] = strtolower($mailConfig['type']);
     }
     if (!empty($mailConfig['username'])) {
         $smtpConfig['username'] = $mailConfig['username'];
     }
     if (!empty($mailConfig['password'])) {
         $smtpConfig['password'] = $mailConfig['password'];
     }
     if (!empty($mailConfig['encryption'])) {
         $smtpConfig['ssl'] = $mailConfig['encryption'];
     }
     $tr = new \Zend_Mail_Transport_Smtp($mailConfig['host'], $smtpConfig);
     Mail::setDefaultTransport($tr);
     ini_set("smtp_port", $mailConfig['port']);
 }
Example #5
0
 protected function setReplyToAsSender(Mail $mail, array $report)
 {
     if (Config::getInstance()->General['scheduled_reports_replyto_is_user_email_and_alias']) {
         if (isset($report['login'])) {
             $userModel = new UserModel();
             $user = $userModel->getUser($report['login']);
             $mail->setReplyTo($user['email'], $user['alias']);
         }
     }
 }
Example #6
0
 /**
  * @dataProvider getEmailFilenames
  */
 public function test_EmailFilenamesAreSanitised($raw, $expected)
 {
     $mail = new Mail();
     $this->assertEquals($expected, $mail->sanitiseString($raw));
 }
Example #7
0
 /**
  * Sends email confirmation link for a password reset request.
  *
  * @param array $user User info for the requested password reset.
  */
 private function sendEmailConfirmationLink($user)
 {
     $login = $user['login'];
     $email = $user['email'];
     // construct a password reset token from user information
     $resetToken = self::generatePasswordResetToken($user);
     $ip = IP::getIpFromHeader();
     $url = Url::getCurrentUrlWithoutQueryString() . "?module=Login&action=confirmResetPassword&login="******"&resetToken=" . urlencode($resetToken);
     // send email with new password
     $mail = new Mail();
     $mail->addTo($email, $login);
     $mail->setSubject(Piwik::translate('Login_MailTopicPasswordChange'));
     $bodyText = str_replace('\\n', "\n", sprintf(Piwik::translate('Login_MailPasswordChangeBody'), $login, $ip, $url)) . "\n";
     $mail->setBodyText($bodyText);
     $fromEmailName = Config::getInstance()->General['login_password_recovery_email_name'];
     $fromEmailAddress = Config::getInstance()->General['login_password_recovery_email_address'];
     $mail->setFrom($fromEmailAddress, $fromEmailName);
     $replytoEmailName = Config::getInstance()->General['login_password_recovery_replyto_email_name'];
     $replytoEmailAddress = Config::getInstance()->General['login_password_recovery_replyto_email_address'];
     $mail->setReplyTo($replytoEmailAddress, $replytoEmailName);
     @$mail->send();
 }
 public function sendReport($reportType, $report, $contents, $filename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles)
 {
     if (self::manageEvent($reportType)) {
         $periods = self::getPeriodToFrequencyAsAdjective();
         $message = Piwik::translate('ScheduledReports_EmailHello');
         $subject = Piwik::translate('General_Report') . ' ' . $reportTitle . " - " . $prettyDate;
         $mail = new Mail();
         $mail->setSubject($subject);
         $fromEmailName = Config::getInstance()->branding['use_custom_logo'] ? Piwik::translate('CoreHome_WebAnalyticsReports') : Piwik::translate('ScheduledReports_PiwikReports');
         $fromEmailAddress = Config::getInstance()->General['noreply_email_address'];
         $attachmentName = $subject;
         $mail->setFrom($fromEmailAddress, $fromEmailName);
         $displaySegmentInfo = false;
         $segmentInfo = null;
         $segment = API::getSegment($report['idsegment']);
         if ($segment != null) {
             $displaySegmentInfo = true;
             $segmentInfo = Piwik::translate('ScheduledReports_SegmentAppliedToReports', $segment['name']);
         }
         switch ($report['format']) {
             case 'html':
                 // Needed when using images as attachment with cid
                 $mail->setType(Zend_Mime::MULTIPART_RELATED);
                 $message .= "<br/>" . Piwik::translate('ScheduledReports_PleaseFindBelow', array($periods[$report['period']], $reportTitle));
                 if ($displaySegmentInfo) {
                     $message .= " " . $segmentInfo;
                 }
                 $mail->setBodyHtml($message . "<br/><br/>" . $contents);
                 break;
             default:
             case 'pdf':
                 $message .= "\n" . Piwik::translate('ScheduledReports_PleaseFindAttachedFile', array($periods[$report['period']], $reportTitle));
                 if ($displaySegmentInfo) {
                     $message .= " " . $segmentInfo;
                 }
                 $mail->setBodyText($message);
                 $mail->createAttachment($contents, 'application/pdf', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $attachmentName . '.pdf');
                 break;
         }
         foreach ($additionalFiles as $additionalFile) {
             $fileContent = $additionalFile['content'];
             $at = $mail->createAttachment($fileContent, $additionalFile['mimeType'], Zend_Mime::DISPOSITION_INLINE, $additionalFile['encoding'], $additionalFile['filename']);
             $at->id = $additionalFile['cid'];
             unset($fileContent);
         }
         // Get user emails and languages
         $reportParameters = $report['parameters'];
         $emails = array();
         if (isset($reportParameters[self::ADDITIONAL_EMAILS_PARAMETER])) {
             $emails = $reportParameters[self::ADDITIONAL_EMAILS_PARAMETER];
         }
         if ($reportParameters[self::EMAIL_ME_PARAMETER] == 1) {
             if (Piwik::getCurrentUserLogin() == $report['login']) {
                 $emails[] = Piwik::getCurrentUserEmail();
             } elseif ($report['login'] == Piwik::getSuperUserLogin()) {
                 $emails[] = Piwik::getSuperUserEmail();
             } else {
                 try {
                     $user = APIUsersManager::getInstance()->getUser($report['login']);
                 } catch (Exception $e) {
                     return;
                 }
                 $emails[] = $user['email'];
             }
         }
         foreach ($emails as $email) {
             if (empty($email)) {
                 continue;
             }
             $mail->addTo($email);
             try {
                 $mail->send();
             } catch (Exception $e) {
                 // If running from piwik.php with debug, we ignore the 'email not sent' error
                 if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
                     throw new Exception("An error occured while sending '{$filename}' " . " to " . implode(', ', $mail->getRecipients()) . ". Error was '" . $e->getMessage() . "'");
                 }
             }
             $mail->clearRecipients();
         }
     }
 }
 public function sendBug()
 {
     Piwik::checkUserHasSomeAdminAccess();
     $idSite = Common::getRequestVar('idSite', null, 'int');
     $email = Common::getRequestVar('email', null);
     $name = Common::getRequestVar('name', null);
     $website = Common::getRequestVar('website', null);
     $message = Common::getRequestVar('message', null);
     $jsonConfig = json_decode(file_get_contents(getcwd() . '/plugins/Chat/plugin.json'), true);
     if ($idSite != null && $email != null && $name != null && $website != null && $message != null) {
         $mail = new Mail();
         $mail->setFrom($email != null ? $email : Piwik::getCurrentUserEmail(), $name != null ? $name : Piwik::getCurrentUserLogin());
         $mail->setSubject("Bug report");
         $mail->setBodyHtml("Piwik Version : " . Version::VERSION . "<br />\n            Chat Version : " . $jsonConfig['version'] . "<br />\n            Website : " . $website . "<br /><br /><br />\n            Message:<br />" . $message);
         $mail->addTo($jsonConfig['authors'][0]['email']);
         try {
             $mail->send();
         } catch (Exception $e) {
             throw new Exception("An error occured while sending 'Bug Report' to " . implode(', ', $mail->getRecipients()) . " Error was '" . $e->getMessage() . "'");
         }
         return true;
     }
 }
 private function assertDateInSubject($period, $expectedDate)
 {
     $alerts = $this->getTriggeredAlerts();
     Mail::setDefaultTransport(new \Zend_Mail_Transport_File());
     $mail = new Mail();
     $this->notifier->sendAlertsPerEmailToRecipient($alerts, $mail, '*****@*****.**', $period, 1);
     $expected = 'New alert for website Piwik test [' . $expectedDate . ']';
     $expecteds = array($expected, \Zend_Mime::encodeQuotedPrintableHeader($expected, 'utf-8'));
     $isExpected = in_array($mail->getSubject(), $expecteds);
     $this->assertTrue($isExpected, $mail->getSubject() . " not found in " . var_export($expecteds, true));
 }
 /**
  * @param array $alerts
  * @param Mail $mail
  * @param string[] $recipient Email addresses
  * @param $period
  * @param $idSite
  */
 protected function sendAlertsPerEmailToRecipient($alerts, Mail $mail, $recipient, $period, $idSite)
 {
     if (empty($recipient) || empty($alerts)) {
         return;
     }
     $prettyDate = $this->getPrettyDateForSite($period, $idSite);
     $websiteName = Site::getNameFor($idSite);
     $mail->setDefaultFromPiwik();
     $mail->addTo($recipient);
     $mail->setSubject(Piwik::translate('CustomAlerts_MailAlertSubject', array($websiteName, $prettyDate)));
     $controller = new Controller();
     $viewHtml = new View('@CustomAlerts/alertHtmlMail');
     $viewHtml->assign('triggeredAlerts', $controller->formatAlerts($alerts, 'html'));
     $mail->setBodyHtml($viewHtml->render());
     $viewText = new View('@CustomAlerts/alertTextMail');
     $viewText->assign('triggeredAlerts', $controller->formatAlerts($alerts, 'text'));
     $viewText->setContentType('text/plain');
     $mail->setBodyText($viewText->render());
     $mail->send();
 }
Example #12
-1
 /**
  * send email to Piwik team and display nice thanks
  * @throws Exception
  */
 function sendFeedback()
 {
     $email = Common::getRequestVar('email', '', 'string');
     $body = Common::getRequestVar('body', '', 'string');
     $category = Common::getRequestVar('category', '', 'string');
     $nonce = Common::getRequestVar('nonce', '', 'string');
     $view = new View('@Feedback/sendFeedback');
     $view->feedbackEmailAddress = Config::getInstance()->General['feedback_email_address'];
     try {
         $minimumBodyLength = 40;
         if (strlen($body) < $minimumBodyLength || strpos($email, 'probe@') !== false || strpos($body, '&lt;probe') !== false) {
             throw new Exception(Piwik::translate('Feedback_ExceptionBodyLength', array($minimumBodyLength)));
         }
         if (!Piwik::isValidEmailString($email)) {
             throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidEmail'));
         }
         if (preg_match('/https?:/i', $body)) {
             throw new Exception(Piwik::translate('Feedback_ExceptionNoUrls'));
         }
         if (!Nonce::verifyNonce('Feedback.sendFeedback', $nonce)) {
             throw new Exception(Piwik::translate('General_ExceptionNonceMismatch'));
         }
         Nonce::discardNonce('Feedback.sendFeedback');
         $mail = new Mail();
         $mail->setFrom(Common::unsanitizeInputValue($email));
         $mail->addTo($view->feedbackEmailAddress, 'Piwik Team');
         $mail->setSubject('[ Feedback form - Piwik ] ' . $category);
         $mail->setBodyText(Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Version::VERSION . "\n" . 'IP: ' . IP::getIpFromHeader() . "\n" . 'URL: ' . Url::getReferrer() . "\n");
         @$mail->send();
     } catch (Exception $e) {
         $view->errorString = $e->getMessage();
         $view->message = $body;
     }
     return $view->render();
 }