示例#1
0
 /**
  * Отправляет email контакам из /siteadmin/contacts/. Вызвается из hourly.php.
  *
  * @return string возможная ошибка
  */
 public function SendMailToContacts()
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/contacts.php';
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/users.php';
     $mails = contacts::GetMails();
     if ($mails) {
         $fromSave = $this->from;
         foreach ($mails as $mail) {
             $user = new users();
             $user->GetUser($user->GetField($mail['user_id'], $ee, 'login'));
             $this->subject = $mail['subject'];
             $attaches = array();
             if ($mail['attaches']) {
                 $files = preg_split('/,/', $mail['attaches']);
                 foreach ($files as $a) {
                     $attaches[] = new CFile('users/' . substr($user->login, 0, 2) . '/' . $user->login . '/upload/' . $a);
                 }
                 $attaches = $this->CreateAttach($attaches);
             }
             $contact_ids = preg_split('/,/', $mail['contact_ids']);
             foreach ($contact_ids as $contact_id) {
                 $contact = contacts::getContactInfo($contact_id);
                 if ($contact['emails']) {
                     $msg_text = $mail['message'];
                     $msg_text = preg_replace('/%CONTACT_NAME%/', $contact['name'], $msg_text);
                     $msg_text = preg_replace('/%CONTACT_SURNAME%/', $contact['surname'], $msg_text);
                     $msg_text = preg_replace('/%CONTACT_COMPANY%/', $contact['company'], $msg_text);
                     foreach ($contact['emails'] as $email) {
                         $this->from = '*****@*****.**';
                         $this->recipient = $contact['name'] . ' <' . $email . '>';
                         $this->message = $msg_text;
                         $this->SmtpMail('text/html', $attaches);
                     }
                 }
             }
             contacts::DeleteMail($mail['id']);
         }
         $this->from = $fromSave;
     }
     return '';
 }