예제 #1
0
 /**
  * Look if the information in $input is ok to send.
  * If yes, send and return a confirmation.
  * Otherwise, return an array that tells what is missing.
  * 
  * required information in $input:
  * sender_id, receiver_id, text
  * 
  * optional fields in $input:
  * reply_to_id, draft_id
  *
  * @param unknown_type $input
  */
 public function sendOrComplain($input)
 {
     // check fields
     $problems = array();
     // Maximum 50 emails can be send using the Invitation-Form
     if (isset($_SESSION['InviteCount']) && $_SESSION['InviteCount'] > 50) {
         $problems['email'] = 'You already sent more than 50 invitations. Maybe that is enough for now?';
     } elseif (!isset($input['email'])) {
         // $problems['receiver'] = 'no receiver was specified.';
         // receiver does not exist.
         $problems['email'] = 'No receiver set.';
     } else {
         // receiver is set, let's check the email addresses:
         $input['email'] = strtolower($input['email']);
         $input['email'] = str_replace(';', ',', $input['email']);
         $input['email'] = str_replace(' ', '', $input['email']);
         $email_array = explode(',', $input['email']);
         foreach ($email_array as $email) {
             if (!isset($email) || !$this->isEmailAddress($email)) {
                 $problems['email'] = 'no correct email addresses.';
             }
         }
     }
     if (!isset($input['sender_id'])) {
         // sender is not set.
         $input['sender_id'] = $_SESSION['IdMember'];
         // $problems['sender_id'] = 'no sender was specified.';
     } else {
         if (!$input['sender_id'] != $_SESSION['IdMember']) {
             // sender is not the person who is logged in.
             $problems['sender_id'] = 'you are not the sender.';
         }
     }
     if (empty($input['text'])) {
         $problems['text'] = 'text is empty.';
     }
     $input['status'] = 'ToSend';
     if (!empty($problems)) {
         $status = false;
     } else {
         // set the sender
         // FIXME: Read & Uncrypt member's email address from the DB and make it the sender-address
         //$sender_uncrypted = new MOD_member()->getFromMembersTable('email');
         $member = $this->createEntity('Member')->findById($_SESSION['IdMember']);
         $sender = MOD_crypt::MemberReadCrypted($member->Email);
         //$sender = PVars::getObj('syshcvol')->MessageSenderMail;
         $result = MOD_mail::sendEmail($input['subject'], $sender, $email_array, false, $input['text']);
         //Now check if Swift actually sends it
         if ($result) {
             $status = true;
             $_SESSION['InviteCount'] = isset($_SESSION['InviteCount']) ? $_SESSION['InviteCount'] + count($email_array) : count($email_array);
         } else {
             MOD_log::write("MOD_mail: Failed to send a mail to " . implode(',', $email_array), "MOD_mail");
             $problems['notsend'] = 'InviteNotSent';
             $status = false;
         }
     }
     return array('status' => $status, 'problems' => $problems);
 }
예제 #2
0
 /**
  * singleton getter
  *
  * @param void
  * @return PApps
  */
 private static function init()
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c();
     }
     return self::$_instance;
 }
예제 #3
0
 /**
  * Sends a mail to member's email address (i.e. for notifications).
  *
  * @param string $subject Email subject.
  * @param string $body Email body.
  */
 public function sendMail($subject, $body)
 {
     $from = PVars::getObj('mailAddresses')->noreply;
     $to = $this->getEmailWithoutPermissionChecks();
     // Create HTML version via purifier (linkify and add paragraphs)
     $purifier = MOD_htmlpure::getAdvancedHtmlPurifier();
     $bodyHTML = $purifier->purify($body);
     if ($this->getPreference('PreferenceHtmlMails', 'Yes') == 'No') {
         $memberPrefersHtml = false;
     } else {
         $memberPrefersHtml = true;
     }
     //clear <br> tags stored in database
     //$body = strip_tags($body);
     // Set language for email translations
     $languageCode = $this->getLanguagePreference();
     // TODO: Error handling
     $result = MOD_mail::sendEmail($subject, $from, $to, false, $bodyHTML, $languageCode, $memberPrefersHtml);
 }
예제 #4
0
 /**
  * actually send out emails using a common BW template
  *
  * @param string $subject   the subject line for the message
  * @param string $from      the email address of the sender
  * @param string $to        the email address of the recipient
  * @param string $body      the plaintext body of the message
  * @param string $title     an optional title to show in the message (HTML H1 tag) (default: false)
  * @param string $body_html the html version of the body (default: false)
  * @param array  $attach    an array of attachments (default: array())
  * @param string $language  the language code used in the message (default: 'en')
  *
  * @return object the result from the MOD_mail::sendEmail call
  */
 protected function sendEmail($subject, $from, $to, $title, $body, $language, $html)
 {
     try {
         return MOD_mail::sendEmail($subject, $from, $to, $title, $body, $language, $html);
     } catch (Exception $e) {
         $this->log("Error (" . date("Y-m-d\\TH:i:sO") . "): Couldn't send mail to " . $to);
         $this->log($e->getTraceAsString());
     }
     return false;
 }
예제 #5
0
 /**
  * Sends a confirmation e-mail
  *
  * @param string $userId
  */
 public function sendActivationMail(Member $member)
 {
     if (!$member) {
         return false;
     }
     $words = new MOD_words();
     $body = $words->get("SignupBodyActivationMail", $member->Firstname, $member->Secondname, $member->Lastname, PVars::getObj('env')->sitename, $member->Username);
     // set the sender & receiver
     $from = PVars::getObj('mailAddresses')->registration;
     $to = $member->getEmailWithoutPermissionChecks();
     // set the subject
     $subject = $words->get('SignupSubjectActivationMail', PVars::getObj('env')->sitename);
     // Use MOD_mail to create and send a message
     $result = MOD_mail::sendEmail($subject, $from, $to, '', $body);
     //Now check if Swift actually sends it
     if (!$result) {
         MOD_log::get()->write(" in signup view " . __FUNCTION__ . ": Failed to send a mail to [" . $to . "]", "signup");
     }
     return $result;
 }