protected function sendMail($project, $emailId)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Get website
     $uri = JUri::getInstance();
     $website = $uri->toString(array("scheme", "host"));
     $emailMode = $this->params->get("email_mode", "plain");
     // Route project URI
     $appSite = JApplicationCms::getInstance('site');
     $router = $appSite->getRouter('site');
     $routedUri = $router->build(CrowdFundingHelperRoute::getDetailsRoute($project->slug, $project->catslug));
     if ($routedUri instanceof JUri) {
         $routedUri = $routedUri->toString();
     }
     if (0 === strpos($routedUri, "/administrator")) {
         $routedUri = str_replace("/administrator", "", $routedUri);
     }
     // Prepare data for parsing
     $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $project->title, "item_url" => $website . $routedUri);
     // Send mail to the administrator
     if (!$emailId) {
         return false;
     }
     $email = new CrowdFundingEmail();
     $email->setDb(JFactory::getDbo());
     $email->load($emailId);
     if (!$email->getSenderName()) {
         $email->setSenderName($app->get("fromname"));
     }
     if (!$email->getSenderEmail()) {
         $email->setSenderEmail($app->get("mailfrom"));
     }
     $recipientName = $project->name;
     $recipientMail = $project->email;
     // Prepare data for parsing
     $data["sender_name"] = $email->getSenderName();
     $data["sender_email"] = $email->getSenderEmail();
     $data["recipient_name"] = $recipientName;
     $data["recipient_email"] = $recipientMail;
     $email->parse($data);
     $subject = $email->getSubject();
     $body = $email->getBody($emailMode);
     $mailer = JFactory::getMailer();
     if (strcmp("html", $emailMode) == 0) {
         // Send as HTML message
         $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML);
     } else {
         // Send as plain text.
         $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN);
     }
     // Log the error.
     if ($result !== true) {
         $this->log->add(JText::sprintf("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_SEND_MAIL_USER", $mailer->ErrorInfo), "PLG_CONTENT_USERE_MAIL_ERROR");
         return false;
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Send emails to the administrator, project owner and the user who have made a donation.
  *
  * @param object $project
  * @param object $transaction
  * @param Joomla\Registry\Registry $params
  */
 protected function sendMails($project, $transaction, $params)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Get website
     $uri = JUri::getInstance();
     $website = $uri->toString(array("scheme", "host"));
     $emailMode = $this->params->get("email_mode", "plain");
     jimport("crowdfunding.currency");
     $currencyId = $params->get("project_currency");
     $currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $params);
     // Prepare data for parsing
     $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $project->title, "item_url" => $website . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($project->slug, $project->catslug)), "amount" => $currency->getAmountString($transaction->txn_amount), "transaction_id" => $transaction->txn_id);
     // Send mail to the administrator
     $emailId = $this->params->get("admin_mail_id", 0);
     if (!empty($emailId)) {
         jimport("crowdfunding.email");
         $email = new CrowdFundingEmail();
         $email->setDb(JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get("fromname"));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get("mailfrom"));
         }
         // Prepare recipient data.
         $componentParams = JComponentHelper::getParams("com_crowdfunding");
         $recipientId = $componentParams->get("administrator_id");
         if (!empty($recipientId)) {
             $recipient = JFactory::getUser($recipientId);
             $recipientName = $recipient->get("name");
             $recipientMail = $recipient->get("email");
         } else {
             $recipientName = $app->get("fromname");
             $recipientMail = $app->get("mailfrom");
         }
         // Prepare data for parsing
         $data["sender_name"] = $email->getSenderName();
         $data["sender_email"] = $email->getSenderEmail();
         $data["recipient_name"] = $recipientName;
         $data["recipient_email"] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = JFactory::getMailer();
         if (strcmp("html", $emailMode) == 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_ADMIN"), $this->debugType);
         }
     }
     // Send mail to project owner
     $emailId = $this->params->get("creator_mail_id", 0);
     if (!empty($emailId)) {
         $email = new CrowdFundingEmail();
         $email->setDb(JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get("fromname"));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get("mailfrom"));
         }
         $user = JFactory::getUser($transaction->receiver_id);
         $recipientName = $user->get("name");
         $recipientMail = $user->get("email");
         // Prepare data for parsing
         $data["sender_name"] = $email->getSenderName();
         $data["sender_email"] = $email->getSenderEmail();
         $data["recipient_name"] = $recipientName;
         $data["recipient_email"] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = JFactory::getMailer();
         if (strcmp("html", $emailMode) == 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             // Log error
             $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_PROJECT_OWNER"), $this->debugType);
         }
     }
     // Send mail to backer
     $emailId = $this->params->get("user_mail_id", 0);
     $investorId = $transaction->investor_id;
     if (!empty($emailId) and !empty($investorId)) {
         $email = new CrowdFundingEmail();
         $email->setDb(JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get("fromname"));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get("mailfrom"));
         }
         $user = JFactory::getUser($investorId);
         $recipientName = $user->get("name");
         $recipientMail = $user->get("email");
         // Prepare data for parsing
         $data["sender_name"] = $email->getSenderName();
         $data["sender_email"] = $email->getSenderEmail();
         $data["recipient_name"] = $recipientName;
         $data["recipient_email"] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = JFactory::getMailer();
         if (strcmp("html", $emailMode) == 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             // Log error
             $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_USER"), $this->debugType);
         }
     }
 }
 protected function sendMail($project, $emailId)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Send mail to the administrator
     if (!$emailId) {
         return false;
     }
     // Get website
     $uri = JUri::getInstance();
     $website = $uri->toString(array("scheme", "host"));
     $emailMode = $this->params->get("email_mode", "plain");
     // Prepare data for parsing
     $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $project->title, "item_url" => $website . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($project->slug, $project->catslug)));
     $email = new CrowdFundingEmail();
     $email->setDb(JFactory::getDbo());
     $email->load($emailId);
     if (!$email->getSenderName()) {
         $email->setSenderName($app->get("fromname"));
     }
     if (!$email->getSenderEmail()) {
         $email->setSenderEmail($app->get("mailfrom"));
     }
     // Prepare recipient data.
     $componentParams = JComponentHelper::getParams("com_crowdfunding");
     $recipientId = $componentParams->get("administrator_id");
     if (!empty($recipientId)) {
         $recipient = JFactory::getUser($recipientId);
         $recipientName = $recipient->get("name");
         $recipientMail = $recipient->get("email");
     } else {
         $recipientName = $app->get("fromname");
         $recipientMail = $app->get("mailfrom");
     }
     // Prepare data for parsing
     $data["sender_name"] = $email->getSenderName();
     $data["sender_email"] = $email->getSenderEmail();
     $data["recipient_name"] = $recipientName;
     $data["recipient_email"] = $recipientMail;
     $email->parse($data);
     $subject = $email->getSubject();
     $body = $email->getBody($emailMode);
     $mailer = JFactory::getMailer();
     if (strcmp("html", $emailMode) == 0) {
         // Send as HTML message
         $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML);
     } else {
         // Send as plain text.
         $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN);
     }
     // Log the error.
     if ($result !== true) {
         $this->log->add(JText::sprintf("PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_SEND_MAIL_ADMIN", $mailer->ErrorInfo), "PLG_CONTENT_ADMIN_EMAIL_ERROR");
         return false;
     }
     return true;
 }