/**
  * @param $mail_to
  * @param null $mail_from
  * @return bool|string
  * @throws \OCA\Owncollab_Chart\PHPMailer\phpmailerException
  */
 private function sendMail($mail_to, $mail_from = null)
 {
     $project = $this->connect->project()->get();
     if ($project['is_share'] != 1 || empty($project['share_link'])) {
         return false;
     }
     $mail_from = $mail_from === null ? 'no-replay@' . Helper::getHost() : $mail_from;
     $nameFrom = 'OwnCollab Project';
     $subject = 'OwnCollab Project Invite';
     $link = Helper::getProtocol() . '://' . Helper::getHost() . '/index.php/s/' . $project['share_link'];
     $nameTo = 'User';
     if (Helper::validEmailAddress($mail_to) && Helper::validEmailAddress($mail_from)) {
         $mail = new PHPMailer();
         $mail->setFrom($mail_from, $nameFrom);
         $mail->addAddress($mail_to, $nameTo);
         $mail->Subject = $subject;
         $mail->Body = Helper::renderPartial($this->appName, 'mailinvite', ['p_name' => $project['name'], 'u_name' => $nameTo, 's_link' => $link, 'protocol' => Helper::getProtocol(), 'domain' => Helper::getHost()]);
         $mail->isHTML();
         if ($mail->send()) {
             return true;
         } else {
             return $mail->ErrorInfo;
         }
     }
     return 'no-valid';
 }
Example #2
0
 /**
  * @param array $conf
  * @return bool|string
  * @throws PHPMailer\phpmailerException
  */
 public static function mailSend(array $conf)
 {
     $to = isset($conf['to']) ? $conf['to'] : false;
     $nameTo = isset($conf['name_to']) ? $conf['name_to'] : 'To';
     $from = isset($conf['from']) ? $conf['from'] : "no-reply@" . \OC::$server->getRequest()->getServerHost();
     $nameFrom = isset($conf['name_from']) ? $conf['name_from'] : 'no-reply';
     $subject = isset($conf['subject']) ? $conf['subject'] : 'OwnCollab message';
     $body = isset($conf['body']) ? $conf['body'] : '';
     $mail = new PHPMailer();
     if (filter_var($to, FILTER_VALIDATE_EMAIL)) {
         $mail->setFrom($from, $nameFrom);
         $mail->addAddress($to, $nameTo);
         $mail->Subject = $subject;
         $mail->Body = $body;
         $mail->isHTML();
         if (!$mail->send()) {
             return $mail->ErrorInfo;
         } else {
             return true;
         }
     }
 }