function ascHtmlMimeMail()
 {
     global $application;
     $res = parent::HtmlMimeMail();
     $mail_settings = modApiFunc("Configuration", "getMailSettings");
     if ($mail_settings['MAIL_TYPE'] == 2) {
         parent::setSMTPParams($mail_settings['MAIL_HOST'], $mail_settings['MAIL_PORT'], NULL, $mail_settings['MAIL_AUTH'] == '1', $mail_settings['MAIL_USER'], $mail_settings['MAIL_PASS']);
     }
     return $res;
 }
 public static function send($from, $to, $subject, $body, array $attachments = null, array $headers = null)
 {
     if (empty($to)) {
         Logger::trace("mail not sent: no recipients: {$subject}");
         return;
     }
     $config = Context::last()->config;
     if (empty($from)) {
         if (!($from = $config->get('modules/mail/from'))) {
             $from = "Molinos.CMS <no-reply@" . MCMS_HOST_NAME . ">";
         }
     }
     if (strstr($body, '<html>') === false) {
         $body = '<html><head><title>' . html::plain($subject) . '</title></head><body>' . $body . '</body></html>';
     }
     if (!is_array($to)) {
         $to = preg_split('/, */', $to, -1, PREG_SPLIT_NO_EMPTY);
     }
     Logger::log(sprintf('to=%s, subject=%s', join(',', $to), $subject), 'mail');
     $mail = new htmlMimeMail();
     if ('smtp' == ($transport = ($server = $config->get('modules/mail/server')) ? 'smtp' : 'mail')) {
         $mail->setSMTPParams($server);
     }
     $mail->setFrom($from);
     $mail->setSubject($subject);
     $mail->setHtml(self::fixhtml($body));
     $mail->setTextCharset('UTF-8');
     $mail->setTextEncoding('base64');
     $mail->setHTMLCharset('UTF-8');
     $mail->setHTMLEncoding('UTF-8');
     $mail->setHeadCharset('UTF-8');
     foreach ((array) $attachments as $file) {
         $mail->addAttachment($file['data'], $file['name'], $file['type']);
     }
     foreach ((array) $headers as $k => $v) {
         if (!empty($v)) {
             $mail->setHeader($k, $v);
         }
     }
     return $mail->send($to, $transport);
 }
Beispiel #3
0
/**
 * Send e-mails
 *
 * @param String $to      Recipient mail address
 * @param String $subject Subject
 * @param String $message Mail content
 * @param String $from    Sender mail address
 * @param Array  $headers Additional mail headers
 *
 * @return Bool Returs true if mail has been sent
 */
function send_mail($to, $subject, $message, $from, $headers = NULL)
{
    global $configuration;
    $mail = new htmlMimeMail();
    if ($configuration['mail_type'] == 'smtp') {
        $type = 'smtp';
        $smtp = $configuration['smtp'];
        $mail->setSMTPParams($smtp['host'], $smtp['port'], $smtp['helo'], $smtp['auth'], $smtp['user'], $smtp['pass']);
    } else {
        $type = 'mail';
    }
    // Set additional mail headers
    $html = false;
    if (is_array($headers)) {
        foreach ($headers as $name => $value) {
            $mail->setHeader($name, $value);
            if (strtolower($name) == 'content-type' and preg_match('#text/html#i', $value)) {
                $mail->setHtmlCharset($configuration['character_set']);
                $mail->setHtml($message);
                $html = true;
            }
            // Set return path
            if (strtolower($name) == 'return-path') {
                $mail->setReturnPath($value);
            }
        }
    }
    $mail->setHeadCharset($configuration['character_set']);
    $mail->setFrom($from);
    $mail->setSubject($subject);
    if ($html != true) {
        $configuration['character_set'];
        $mail->setTextCharset($configuration['character_set']);
        $mail->setText($message);
    }
    $result = $mail->send(array($to), $type);
    if ($result) {
        return true;
    }
}
Beispiel #4
0
 /**
  * Replace placeholders in mail templates and send
  * e-mails.
  */
 function send_mail($mail_content, $content_data, $post_data = null)
 {
     global $text_wrap, $my_sendmail, $send_alternative_mail, $debug_mode, $sender_count, $sender_duration, $recipient_count, $recipient_duration, $txt, $remove_tags, $tplt, $configuration;
     $multiple = $this->collect_multiples($post_data);
     $mail_content = $this->replace_multiples($mail_content, $multiple);
     for ($i = 0; $i < count($mail_content); $i++) {
         /**
          * Replace placeholder with form, text (from language
          * file) and environment data
          */
         $mail_content[$i] = $this->replace_values($mail_content[$i], $post_data);
         $mail_content[$i] = $this->replace_values($mail_content[$i], $txt);
         $mail_content[$i] = $this->replace_values($mail_content[$i], $content_data);
         $mail_content[$i] = $this->replace_values($mail_content[$i], $this->get_environment_var($_SERVER));
         //$mail_content[$i] = $this->replace_values($mail_content[$i], $url);
         /**
          * Remove unselected value placeholders
          */
         $mail_content[$i] = $this->remove_values($mail_content[$i]);
         /**
          * Remove tags
          */
         // $mail_content[$i] = $this->clean_output($mail_content[$i], $remove_tags);
         /**
          * Strip slashes
          */
         $final_mail_content = stripslashes($mail_content[$i]);
         if ($this->validate_to($final_mail_content) == false) {
             continue;
         }
         /**
          * Check whether the user is allowed to send e-mails
          * with or to a certain e-mail address.
          */
         $sender = $this->get_header_info($mail_content[$i], 'From');
         $recipient = $this->get_header_info($mail_content[$i], 'To');
         // Check if recipient is blocked by domain
         if (sizeof($configuration['recipients_domains']) > 0) {
             foreach ($configuration['recipients_domains'] as $recipient_domain) {
                 $domain = '#' . preg_quote(trim($recipient_domain)) . '#';
                 if (preg_match($domain, $recipient) === 1) {
                     return array('status' => 'failed', 'message' => array(), 'mail_content' => $mail_content[$i]);
                 }
             }
         }
         if ($tplt == 'recom') {
             if ($limit = $this->check_value_limit($sender, $sender_count, $sender_duration, 4, $txt['txt_sender_expiration'])) {
                 $message[] = array('message' => $limit, 'fields' => '');
             }
             if ($limit = $this->check_value_limit($recipient, $recipient_count, $recipient_duration, 5, $txt['txt_recipient_expiration'])) {
                 $message[] = array('message' => $limit, 'fields' => '');
             }
             if (isset($message) and !empty($message)) {
                 return array('status' => 'failed', 'message' => $message);
             }
         }
         /**
          * Start attachment handling
          */
         $send_attachments = false;
         if (!empty($this->attachments) and is_array($this->attachments)) {
             $send_alternative_mail = 'yes';
             $send_attachments = true;
         }
         if (isset($configuration['attach_mail_vars']) and is_array($configuration['attach_mail_vars']) and sizeof($configuration['attach_mail_vars']) > 0) {
             $send_alternative_mail = 'yes';
             $send_attachments = true;
         }
         /**
          * Get sendmail path from php ini settings or use the
          * value of $my_sendmail.
          */
         if ($send_alternative_mail != 'yes') {
             $sendmail = @ini_get('sendmail_path');
             debug_mode($sendmail, 'ini_get()');
             if (empty($sendmail)) {
                 $sendmail = "/usr/sbin/sendmail -t ";
                 debug_mode($sendmail, 'empty($sendmail)');
             }
             if (isset($my_sendmail) and !empty($my_sendmail)) {
                 $sendmail = $my_sendmail;
                 debug_mode(array('$my_sendmail', $sendmail));
             }
             /**
              * Try to send e-mail by using popen() to access
              * sendmail.
              */
             if ($fd = @popen($sendmail, "w")) {
                 if (!@fputs($fd, $final_mail_content . "\n")) {
                     $send_alternative_mail = 'yes';
                     debug_mode(array($txt['txt_popen_error'] . ' - fputs()', gettype($fd), $fd));
                 }
                 pclose($fd);
             } else {
                 $send_alternative_mail = 'yes';
                 debug_mode(array($txt['txt_popen_error'] . ' - popen()', gettype($fd), $fd));
             }
             debug_mode($final_mail_content, 'Mail Content popen()');
         }
         /**
          * If popen() - or fputs() - fails, extract mail
          * header from the template and use the PHP  function
          * mail().
          */
         if ($send_alternative_mail == 'yes') {
             $header_info = explode("\n", $final_mail_content);
             $mail_subject = '';
             $mail_header = $this->mail_headers;
             $mail_header = join($mail_header, '|');
             unset($additional_headers);
             $attachment_headers = array();
             for ($k = 0; $k < count($header_info); $k++) {
                 $clean_header = trim($header_info[$k]);
                 if (empty($clean_header)) {
                     break;
                 }
                 if (preg_match("/^From:/i", $header_info[$k])) {
                     $mail_from = trim(preg_replace("/From:/i", '', $header_info[$k]));
                     $attachment_headers['From'] = $mail_from;
                     unset($header_info[$k]);
                     continue;
                 }
                 if (preg_match("/^To:/i", $header_info[$k])) {
                     $mail_recipient = trim(preg_replace("/^To:/i", '', $header_info[$k]));
                     unset($header_info[$k]);
                     continue;
                 }
                 if (preg_match("/^Subject:/i", $header_info[$k])) {
                     $mail_subject = trim(preg_replace("/^Subject:/i", '', $header_info[$k]));
                     unset($header_info[$k]);
                     continue;
                 }
                 if (preg_match("/^X-Form-Mail-Attachment:/i", $header_info[$k])) {
                     if (trim(str_replace('X-Form-Mail-Attachment:', '', $header_info[$k])) == 'no') {
                         $send_attachments = false;
                     }
                     unset($header_info[$k]);
                     continue;
                 }
                 if (preg_match("/^" . $mail_header . "/i", $header_info[$k], $match)) {
                     $additional_headers[] = $header_info[$k];
                     $attachment_headers[str_replace(':', '', $match[0])] = trim(preg_replace("/" . $match[0] . "/i", '', $header_info[$k]));
                     unset($header_info[$k]);
                     continue;
                 }
             }
             if (isset($header_info) and is_array($header_info)) {
                 $new_mail_content = trim(implode($header_info, "\n"));
                 $new_mail_content = str_replace("\r", '', $new_mail_content);
             } else {
                 $new_mail_content = '';
             }
             //                if (isset($additional_headers) and is_array($additional_headers)) {
             //                    $additional_headers = implode($additional_headers, "\n");
             //                } else {
             //                    $additional_headers = '';
             //                }
             /**
              * Wrap mail content (and only mail content - not
              * headers).
              */
             $new_mail_content = $this->wrap_content($new_mail_content, $text_wrap);
             /**
              * Send mail using simple mail function
              */
             if (!$send_attachments and $debug_mode != 'on' and $mail_recipient != '') {
                 //  @mail ($mail_recipient, $mail_subject, $new_mail_content, $additional_headers);
                 send_mail($mail_recipient, $mail_subject, $new_mail_content, $mail_from, $attachment_headers);
             }
             /**
              * Send mail using mail class
              */
             if ($send_attachments and $debug_mode != 'on' and $mail_recipient != '') {
                 $att = new htmlMimeMail();
                 // Switch to smtp mode
                 if ($configuration['mail_type'] == 'smtp') {
                     $type = 'smtp';
                     $smtp = $configuration['smtp'];
                     $att->setSMTPParams($smtp['host'], $smtp['port'], $smtp['helo'], $smtp['auth'], $smtp['user'], $smtp['pass']);
                 } else {
                     $type = 'mail';
                 }
                 // Register file attachments in mime class
                 foreach ($this->attachments as $file_name) {
                     $att->addAttachment($att->getFile($file_name['new']), $file_name['old']);
                 }
                 //Manage mail var attachments
                 if (isset($configuration['attach_mail_vars']) and is_array($configuration['attach_mail_vars']) and sizeof($configuration['attach_mail_vars']) > 0) {
                     foreach ($configuration['attach_mail_vars'] as $attach_type) {
                         if ($attach_type == 'vcard') {
                             $attach_config = array('mailvars' => $post_data, 'type' => G10E_ATTACH_TYPE_VCARD, 'control' => $this->control_fields);
                             if ($res = attach_mail_variables::get_content($attach_config)) {
                                 $att->addAttachment($res, 'vcard.vcf');
                             }
                         }
                         if ($attach_type == 'csv') {
                             $attach_config = array('mailvars' => $post_data, 'type' => G10E_ATTACH_TYPE_CSV, 'control' => $this->control_fields, 'csv_head' => true);
                             if ($res = attach_mail_variables::get_content($attach_config)) {
                                 $att->addAttachment($res, 'csv.csv');
                             }
                         }
                     }
                 }
                 // Register headers in mime class
                 $html = false;
                 if (isset($attachment_headers) and is_array($attachment_headers)) {
                     foreach ($attachment_headers as $key => $val) {
                         $att->setHeader($key, $val);
                         if ($key == 'Content-Type' and preg_match('#text/html#i', $val)) {
                             $att->setHtmlCharset($configuration['character_set']);
                             $att->setHtml($new_mail_content);
                             $html = true;
                         }
                     }
                 }
                 $att->setHeadCharset($configuration['character_set']);
                 $att->setSubject($mail_subject);
                 if ($html != true) {
                     $att->setTextCharset($configuration['character_set']);
                     $att->setText($new_mail_content);
                 }
                 $att->send(array($mail_recipient), $type);
             }
             debug_mode($mail_recipient, 'Mail Recipient mail()');
             debug_mode($mail_subject, 'Mail Subject mail()');
             debug_mode($new_mail_content, 'Mail Content mail()');
             debug_mode($additional_headers, 'Mail Additional Headers mail()');
         }
     }
     // -re- for
     $this->mail_content = $mail_content[0];
     return array('status' => 'ok', 'mail_content' => $this->mail_content);
 }
Beispiel #5
0
     $mail->addAttachment($a1, $_REQUEST["attach1"], $_REQUEST["attach1type"]);
     @unlink('temp/mail_attachs/' . $_REQUEST["attach1file"]);
 }
 if ($_REQUEST["attach2"]) {
     check_ticket('webmail');
     $a2 = $mail->getFile('temp/mail_attachs/' . $_REQUEST["attach2file"]);
     $mail->addAttachment($a2, $_REQUEST["attach2"], $_REQUEST["attach2type"]);
     @unlink('temp/mail_attachs/' . $_REQUEST["attach2file"]);
 }
 if ($_REQUEST["attach3"]) {
     check_ticket('webmail');
     $a3 = $mail->getFile('temp/mail_attachs/' . $_REQUEST["attach3file"]);
     $mail->addAttachment($a3, $_REQUEST["attach3"], $_REQUEST["attach3type"]);
     @unlink('temp/mail_attachs/' . $_REQUEST["attach3file"]);
 }
 $mail->setSMTPParams($current["smtp"], $current["smtpPort"], '', $current["useAuth"], $current["username"], $current["pass"]);
 if (isset($_REQUEST["useHTML"]) && $_REQUEST["useHTML"] == 'on') {
     $mail->setHTML($_REQUEST["body"], strip_tags($_REQUEST["body"]));
 } else {
     $mail->setText($_REQUEST["body"]);
 }
 $to_array_1 = split('[, ;]', $_REQUEST["to"]);
 $to_array = array();
 foreach ($to_array_1 as $to_1) {
     if (!empty($to_1)) {
         $to_array[] = $to_1;
     }
 }
 $to_array = $webmaillib->parse_nicknames($to_array);
 // Get email addresses not in the address book
 $not_contacts = $webmaillib->are_contacts($to_array, $user);
Beispiel #6
0
error_reporting(E_ALL);
include 'htmlMimeMail.php';
/**
* Example of usage. This example shows
* how to use the class to send Bcc: 
* and/or Cc: recipients.
*
* Create the mail object.
*/
$mail = new htmlMimeMail();
/**
* We will just send a text email
*/
$text = $mail->getFile('example.txt');
$mail->setText($text);
/**
* Send the email using smtp method. The setSMTPParams()
* method simply changes the HELO string to example.com
* as localhost and port 25 are the defaults.
*/
$mail->setSMTPParams('localhost', 25, 'example.com');
$mail->setReturnPath('*****@*****.**');
$mail->setBcc('*****@*****.**');
$mail->setCc('Carbon Copy <*****@*****.**>');
$result = $mail->send(array('postmaster@localhost'), 'smtp');
// These errors are only set if you're using SMTP to send the message
if (!$result) {
    print_r($mail->errors);
} else {
    echo 'Mail sent!';
}
 /**
  * Initialise un objet htmlMimeMail pour l'envoi.
  *
  * @return htmlMimeMail
  */
 private function _createMailer()
 {
     Copix::RequireOnce(COPIX_PATH . '../htmlMimeMail/htmlMimeMail.php');
     $mail = new htmlMimeMail();
     $mail->setReturnPath(CopixConfig::get('|mailFrom'));
     $mail->setFrom('"' . CopixConfig::get('|mailFromName') . '" <' . CopixConfig::get('|mailFrom') . '>');
     $mail->setHeader('X-Mailer', 'COPIX (http://copix.org) with HTML Mime mail class (http://www.phpguru.org)');
     if (CopixConfig::get('|mailMethod') == 'smtp') {
         $auth = CopixConfig::get('|mailSmtpAuth') == '' ? null : CopixConfig::get('|mailSmtpAuth');
         $pass = CopixConfig::get('|mailSmtpPass') == '' ? null : CopixConfig::get('|mailSmtpPass');
         $hasAuth = $auth != null;
         $port = CopixConfig::exists('|mailSmtpPort') && CopixConfig::get('|mailSmtpPort') ? CopixConfig::get('|mailSmtpPort') : null;
         $mail->setSMTPParams(CopixConfig::get('|mailSmtpHost'), $port, null, $hasAuth, $auth, $pass);
     }
     return $mail;
 }