コード例 #1
0
ファイル: mail_handler.php プロジェクト: cls1991/ryzomcore
 /**
  * Wrapper for sending emails, creates the content of the email
  * Based on the type of the ticketing mail it will create a specific email, it will use the language.ini files to load the correct language of the email for the receiver.
  * Also if the $TICKET_MAILING_SUPPORT is set to false or if the user's personal 'ReceiveMail' entry is set to false then no mail will be sent.
  * @param $receiver if integer, then it refers to the id of the user to whom we want to mail, if it's a string(email-address) then we will use that.
  * @param $ticketObj the ticket object itself, this is being used for including ticket related information into the email.
  * @param $content the content of a reply or new ticket
  * @param $type REPLY, NEW, WARNAUTHOR, WARNSENDER, WARNUNKNOWNSENDER
  * @param $sender (default = 0 (if it is not forwarded)) else use the id of the support group to which the ticket is currently forwarded, the support groups email address will be used to send the ticket.
  */
 public static function send_ticketing_mail($receiver, $ticketObj, $content, $type, $sender = 0)
 {
     global $TICKET_MAILING_SUPPORT;
     if ($TICKET_MAILING_SUPPORT) {
         global $MAIL_LOG_PATH;
         //error_log("Receiver: {$receiver}, content: {$content}, type: {$type}, SendingId: {$sender} \n", 3, $MAIL_LOG_PATH);
         if ($sender == 0) {
             //if it is not forwarded (==public == which returns 0) then make it NULL which is needed to be placed in the DB.
             $sender = NULL;
         }
         global $AMS_TRANS;
         if (is_numeric($receiver)) {
             $webUser = new WebUsers($receiver);
             $lang = $webUser->getLanguage();
         } else {
             global $DEFAULT_LANGUAGE;
             $lang = $DEFAULT_LANGUAGE;
         }
         $variables = parse_ini_file($AMS_TRANS . '/' . $lang . '.ini', true);
         $mailText = array();
         foreach ($variables['email'] as $key => $value) {
             $mailText[$key] = $value;
         }
         switch ($type) {
             case "REPLY":
                 $webUser = new WebUsers($receiver);
                 if ($webUser->getReceiveMail()) {
                     $subject = $mailText['email_subject_new_reply'] . $ticketObj->getTId() . "]";
                     $txt = $mailText['email_body_new_reply_1'] . $ticketObj->getTId() . $mailText['email_body_new_reply_2'] . $ticketObj->getTitle() . $mailText['email_body_new_reply_3'] . $content . $mailText['email_body_new_reply_4'];
                     self::send_mail($receiver, $subject, $txt, $ticketObj->getTId(), $sender);
                 }
                 break;
             case "NEW":
                 $webUser = new WebUsers($receiver);
                 if ($webUser->getReceiveMail()) {
                     $subject = $mailText['email_subject_new_ticket'] . $ticketObj->getTId() . "]";
                     $txt = $mailText['email_body_new_ticket_1'] . $ticketObj->getTId() . $mailText['email_body_new_ticket_2'] . $ticketObj->getTitle() . $mailText['email_body_new_ticket_3'] . $content . $mailText['email_body_new_ticket_4'];
                     self::send_mail($receiver, $subject, $txt, $ticketObj->getTId(), $sender);
                 }
                 break;
             case "WARNAUTHOR":
                 if (is_numeric($sender)) {
                     $sender = Ticket_User::get_email_by_user_id($sender);
                 }
                 $subject = $mailText['email_subject_warn_author'] . $ticketObj->getTId() . "]";
                 $txt = $mailText['email_body_warn_author_1'] . $ticketObj->getTitle() . $mailText['email_body_warn_author_2'] . $sender . $mailText['email_body_warn_author_3'] . $sender . $mailText['email_body_warn_author_4'];
                 self::send_mail($receiver, $subject, $txt, $ticketObj->getTId(), NULL);
                 break;
             case "WARNSENDER":
                 $subject = $mailText['email_subject_warn_sender'];
                 $txt = $mailText['email_body_warn_sender'];
                 self::send_mail($receiver, $subject, $txt, $ticketObj->getTId(), NULL);
                 break;
             case "WARNUNKNOWNSENDER":
                 $subject = $mailText['email_subject_warn_unknown_sender'];
                 $txt = $mailText['email_body_warn_unknown_sender'];
                 self::send_mail($receiver, $subject, $txt, $ticketObj->getTId(), NULL);
                 break;
         }
     }
 }