Esempio n. 1
0
 /**
  * Actually carry out the action.
  */
 public function doAction($form_params, $form_data, $fields)
 {
     global $conf;
     $mail = new Horde_Mime_Mail();
     $mail->addHeader('From', $form_params['from']);
     $mail->addHeader('Subject', $form_params['subject']);
     $mail->addHeader('To', $form_params['to']);
     if (!empty($form_params['cc'])) {
         $mail->addHeader('Cc', $form_params['cc']);
     }
     if (!empty($form_params['bcc'])) {
         $mail->addHeader('Bcc', $form_params['bcc']);
     }
     $body = '';
     foreach ($fields as $field) {
         $value = array_shift($form_data);
         switch ($field['field_type']) {
             case 'file':
             case 'image':
                 if (!empty($value['file'])) {
                     $mail->addAttachment($value['file'], $value['name'], $value['type']);
                 }
                 break;
             default:
                 $body .= $field['field_label'] . ': ' . $this->_formatFormData($value) . "\n";
                 break;
         }
     }
     $mail->setBody($body);
     return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
 }
Esempio n. 2
0
 /**
  * Notify user
  *
  * @param mixed  $user        User or array of users to send notification to
  * @param string $subject     Subject of message
  * @param string $body        Body of message
  * @param array  $attachments Attached files
  *
  * @return true on succes, PEAR_Error on failure
  */
 public function notify($user, $subject, $body, $attachments = array())
 {
     if (empty($user)) {
         return true;
     }
     $mail = new Horde_Mime_Mail(array('body' => $body, 'Subject' => $subject, 'From' => $this->_params['from_addr'], 'User-Agent' => 'Folks ' . $GLOBALS['registry']->getVersion(), 'X-Originating-IP' => $_SERVER['REMOTE_ADDR'], 'X-Remote-Browser' => $_SERVER['HTTP_USER_AGENT']));
     foreach ($attachments as $file) {
         if (file_exists($file)) {
             $mail->addAttachment($file, null, null, 'UTF-8');
         }
     }
     if (is_string($user)) {
         $user = array($user);
     }
     foreach ($user as $recipent) {
         $to = $this->_getUserFromAddr($recipent);
         if (empty($to)) {
             continue;
         }
         $mail->addHeader('To', $to, true);
         $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
     }
     return true;
 }
Esempio n. 3
0
    public function testAddAttachment()
    {
        $mail = new Horde_Mime_Mail(array('Subject' => 'My Subject', 'body' => "This is\nthe body", 'To' => '*****@*****.**', 'From' => '*****@*****.**', 'charset' => 'iso-8859-15'));
        $mail->addAttachment(__DIR__ . '/fixtures/attachment.bin');
        $mail->addAttachment(__DIR__ . '/fixtures/uudecode.txt', 'my_name.html', 'text/html', 'iso-8859-15');
        $dummy = new Horde_Mail_Transport_Mock();
        $mail->send($dummy);
        $sent = str_replace("\r\n", "\n", $dummy->sentMessages[0]);
        $this->assertStringMatchesFormat('Subject: My Subject
To: recipient@example.com
From: sender@example.com
Message-ID: <*****@*****.**>
User-Agent: Horde Application Framework %d
Date: %s, %d %s %d %d:%d:%d %s%d
Content-Type: multipart/mixed; boundary="=_%s"
MIME-Version: 1.0', $sent['header_text']);
        $this->assertStringMatchesFormat("This message is in MIME format.\n\n--=_%s\nContent-Type: text/plain; charset=iso-8859-15; format=flowed; DelSp=Yes\n\nThis is\nthe body\n\n--=_%s\nContent-Type: application/octet-stream; name=attachment.bin\nContent-Disposition: attachment; filename=attachment.bin\nContent-Transfer-Encoding: base64\n\nWnfDtmxmIEJveGvDpG1wZmVyIGphZ2VuIFZpa3RvciBxdWVyIMO8YmVyIGRlbiBncm/Dn2VuIFN5\nbHRlciBEZWljaC4K\n--=_%s\nContent-Type: text/html; charset=iso-8859-15; name=my_name.html\nContent-Disposition: attachment; filename=my_name.html\n\n\nIgnore this text.\n\nbegin 644 test.txt\n+5&5S=\"!S=')I;F<`\n`\nend\n\nMore text to ignore.\n\nbegin 755 test2.txt\n*,FYD('-T<FEN9P``\n`\nend\n\n\n--=_%s--\n", $sent['body']);
        $this->assertEquals(array('*****@*****.**'), $sent['recipients']);
    }
Esempio n. 4
0
             $redirect_url->redirect();
         }
         /* Add user's name to the email address if provided. */
         if ($name) {
             $addr_ob = new Horde_Mail_Rfc822_Address($email);
             if (is_null($addr_ob->host)) {
                 $addr_ob->host = $conf['problems']['maildomain'];
             }
             $addr_ob->personal = $name;
             $email = $addr_ob->writeAddress(true);
         }
         $mail = new Horde_Mime_Mail(array('body' => $body, 'Subject' => _("[Problem Report]") . ' ' . $subject, 'To' => $conf['problems']['email'], 'From' => $email));
         $mail->addHeader('Sender', 'horde-problem@' . $conf['problems']['maildomain']);
         /* Add attachment. */
         if ($attachment) {
             $mail->addAttachment($attachment['tmp_name'], $attachment['name'], $attachment['type']);
         }
         try {
             $mail->send($injector->getInstance('Horde_Mail'));
             /* Success. */
             Horde::log(sprintf("%s Message sent to %s from %s", $_SERVER['REMOTE_ADDR'], preg_replace('/^.*<([^>]+)>.*$/', '$1', $conf['problems']['email']), preg_replace('/^.*<([^>]+)>.*$/', '$1', $email)), 'INFO');
             /* Return to previous page and exit this script. */
             $redirect_url->redirect();
         } catch (Horde_Exception $e) {
             $notification->push($e);
         }
     }
     break;
 case 'cancel_problem_report':
     $redirect_url->redirect();
     break;
Esempio n. 5
0
 /**
  * Send email with attachments
  *
  * @param string $from       From address
  * @param string $subject    Subject of message
  * @param string $body       Body of message
  * @param array  $attaches   Path of file to attach
  *
  * @return true on succes, PEAR_Error on failure
  */
 public static function sendMail($to, $subject, $body, $attaches = array())
 {
     $mail = new Horde_Mime_Mail(array('body' => $body, 'Subject' => $subject, 'To' => $to, 'From' => $GLOBALS['conf']['support'], 'User-Agent' => 'Folks ' . $GLOBALS['registry']->getVersion(), 'X-Originating-IP' => $_SERVER['REMOTE_ADDR'], 'X-Remote-Browser' => $_SERVER['HTTP_USER_AGENT']));
     foreach ($attaches as $file) {
         if (file_exists($file)) {
             $mail->addAttachment($file, null, null, 'UTF-8');
         }
     }
     return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
 }