/**
  * Define the `sendmail` path if so
  */
 public function __construct()
 {
     $sendmail_path = Mailer::getInstance()->getOption('sendmail_path');
     if (!empty($sendmail_path)) {
         @ini_set('sendmail_path', $sendmail_path);
     }
 }
Esempio n. 2
0
 /**
  * Format a text with a special encoding
  *
  * @param string $txt The text to format
  * @param string $type The type of the encoding : 'plain' or 'ascii'
  * @param bool $spaces Replace all spaces with underscores or not (default is FALSE)
  * @return string The transformed text
  */
 public static function formatText($txt = '', $type = 'plain', $spaces = false)
 {
     switch ($type) {
         case 'ascii':
             $_txt = '';
             if ($spaces == true) {
                 $txt = str_replace(' ', '_', $txt);
             }
             for ($i = 0; $i < strlen($txt); $i++) {
                 $_txt .= self::charAscii($txt[$i]);
             }
             $txt = $_txt;
             break;
         default:
             break;
     }
     $mailer = Mailer::getInstance();
     $limit = $mailer->getOption('wordwrap_limit');
     $formated = '';
     foreach (explode("\n", $txt) as $_line) {
         $_line = trim($_line);
         if (strlen($_line) > $limit) {
             $_line = wordwrap($_line, $limit, Mailer::$LINE_ENDING);
         }
         if (strlen($_line)) {
             $formated .= $_line . Mailer::$LINE_ENDING;
         }
     }
     return $formated;
 }
 public function treat(&$email = array())
 {
     if (empty($this->posted)) {
         return null;
     }
     $ok_email = false;
     // MimeEmail object
     $sender = \MimeMailer\Mailer::getInstance();
     // from
     $posted_sender = $this->isPosted('sender');
     //var_export($posted_sender);
     if (!empty($posted_sender['email'])) {
         $sender->getMessage()->setFrom($posted_sender['email'], !empty($posted_sender['name']) ? $posted_sender['name'] : null);
     } else {
         $email[] = 'No sender defined!';
         return false;
     }
     // recipients
     $posted_recips = $this->isPosted('recipients');
     //var_export($posted_recips);
     if (!empty($posted_recips['to'])) {
         $sender->getMessage()->setTo($posted_recips['to']);
     } else {
         $email[] = 'No classic recipient defined!';
         return false;
     }
     if (!empty($posted_recips['cc'])) {
         $sender->getMessage()->setCc($posted_recips['cc']);
     }
     if (!empty($posted_recips['bcc'])) {
         $sender->getMessage()->setBcc($posted_recips['bcc']);
     }
     // contents
     $posted_contents = $this->isPosted('contents');
     //var_export($posted_contents);
     if (!empty($posted_contents['subject'])) {
         $sender->getMessage()->setSubject($posted_contents['subject']);
     } else {
         $email[] = 'No subject defined!';
         return false;
     }
     if (!empty($posted_contents['plain_text'])) {
         $sender->getMessage()->setText($posted_contents['plain_text']);
     }
     if (!empty($posted_contents['html'])) {
         $sender->getMessage()->setHtml($posted_contents['html']);
     }
     // attachments
     $posted_attachments = $this->isPosted('attachments');
     //var_export($posted_attachments);
     if (!empty($posted_attachments['files'])) {
         $sender->getMessage()->setAttachment($posted_attachments['files']);
     }
     // options
     $posted_options = $this->isPosted('options');
     //var_export($posted_options);
     if (!empty($posted_options['reply'])) {
         $sender->getMessage()->setReplyTo($posted_options['reply']);
     }
     if (!empty($posted_options['follow'])) {
         $sender->getMessage()->setFollowupTo($posted_options['follow']);
     }
     if (!empty($posted_options['errors'])) {
         $sender->getMessage()->setErrorsTo($posted_options['errors']);
     }
     if (!empty($posted_options['notify'])) {
         $sender->getMessage()->setDispositionNotificationTo($posted_options['notify']);
     }
     // sending / spooling
     $ok_email = $sender->send(1);
     $email = array('errors' => $sender->getErrors(), 'infos' => $sender->getInfos(), 'message' => $sender->getMessage()->getMessage());
     //        $email = $sender;
     return $ok_email;
 }