Beispiel #1
0
 function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     $sender = get_mailsender();
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
     if (!is_array($attachments)) {
         $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     }
     // Headers
     if (empty($headers)) {
         $headers = array();
     } else {
         if (!is_array($headers)) {
             // Explode the headers out, so this function can take both
             // string headers and an array of headers.
             $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers));
         } else {
             $tempheaders = $headers;
         }
         $headers = array();
         // If it actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     if (false !== stripos($header, 'boundary=')) {
                         $parts = preg_split('/boundary=/i', trim($header));
                         $boundary = trim(str_replace(array("'", '"'), '', $parts[1]));
                     }
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 switch (strtolower($name)) {
                     // Mainly for legacy -- process a From: header if it's there
                     case 'from':
                         if (strpos($content, '<') !== false) {
                             // So... making my life hard again?
                             $from_name = substr($content, 0, strpos($content, '<') - 1);
                             $from_name = str_replace('"', '', $from_name);
                             $from_name = trim($from_name);
                             $from_email = substr($content, strpos($content, '<') + 1);
                             $from_email = str_replace('>', '', $from_email);
                             $from_email = trim($from_email);
                         } else {
                             $from_name = trim($content);
                         }
                         break;
                     case 'content-type':
                         if (strpos($content, ';') !== false) {
                             list($type, $charset) = explode(';', $content);
                             $content_type = trim($type);
                             if (false !== stripos($charset, 'charset=')) {
                                 $charset = trim(str_replace(array('charset=', '"'), '', $charset));
                             } elseif (false !== stripos($charset, 'boundary=')) {
                                 $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset));
                                 $charset = '';
                             }
                         } else {
                             $content_type = trim($content);
                         }
                         break;
                     case 'cc':
                         $cc = array_merge((array) $cc, explode(',', $content));
                         break;
                     case 'bcc':
                         $bcc = array_merge((array) $bcc, explode(',', $content));
                         break;
                     default:
                         // Add it to our grand headers array
                         $headers[trim($name)] = trim($content);
                         break;
                 }
             }
         }
     }
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = '';
     }
     /* If we don't have an email from the input headers default to $noreply
      * Some hosts will block outgoing mail from this address if it doesn't exist but
      * there's no easy alternative. Defaulting to admin_email might appear to be another
      * option but some hosts may refuse to relay mail from an unknown domain. See
      * http://trac.wordpress.org/ticket/5007.
      */
     if (!isset($from_email)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = $replyto;
     }
     // Set destination addresses
     if (!is_array($to)) {
         $to = explode(',', $to);
     }
     // Set Content-Type and charset
     // If we don't have a content-type from the input headers
     if (!isset($content_type)) {
         $content_type = 'text/html';
     }
     $content_type = apply_filters('wp_mail_content_type', $content_type);
     $msg = new message($content_type, $log, $debug, $logpath);
     $msg->set_to($to);
     $msg->set_cc($cc);
     $msg->set_bcc($bcc);
     $msg->set_subject($subject);
     $msg->set_bodyContent(nl2br($message));
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $msg->set_attachByPathOnAppServer(basename($attachment), $attachment);
         }
     }
     //add message to mailsender
     if (!$sender->add($msg)) {
         return false;
     }
     // Send!
     $result = $sender->send_mail();
     return $result;
 }
Beispiel #2
0
    /**
     * Checks if the user is member of clients group and if it should be member of it
     * @author Albert Pérez Monfort
     * @return bool true authetication succesful
     */
    public static function sendMail(Zikula_Event $event) {
        $args = $event->getArgs();
/*
        $args['html'] = FormUtil::getPassedValue('html', isset($args['html']) ? $args['html'] : 0, 'POST');
        $args['toaddress'] = FormUtil::getPassedValue('toaddress', isset($args['toaddress']) ? $args['toaddress'] : null, 'POST');
        $args['cc'] = FormUtil::getPassedValue('cc', isset($args['cc']) ? $args['cc'] : null, 'POST');
        $args['bcc'] = FormUtil::getPassedValue('bcc', isset($args['bcc']) ? $args['bcc'] : null, 'POST');
        $args['subject'] = FormUtil::getPassedValue('subject', isset($args['subject']) ? $args['subject'] : null, 'POST');
        $args['body'] = FormUtil::getPassedValue('body', isset($args['body']) ? $args['body'] : null, 'POST');
        $args['attachments'] = FormUtil::getPassedValue('attachments', isset($args['attachments']) ? $args['attachments'] : array(), 'POST');
        $args['stringattachments'] = FormUtil::getPassedValue('stringattachments', isset($args['stringattachments']) ? $args['stringattachments'] : array(), 'POST');
        $args['embeddedimages'] = FormUtil::getPassedValue('embeddedimages', isset($args['embeddedimages']) ? $args['embeddedimages'] : array(), 'POST');
*/
        // include php mailsender class file
        if (file_exists($file = "modules/SiriusXtecMailer/includes/mailsender.class.php")) {
            require_once($file);
        } else {
            return false;
        }

        // include php message class file
        if (file_exists($file = "modules/SiriusXtecMailer/includes/message.class.php")) {
            require_once($file);
        } else {
            return false;
        }

        $enabled = ModUtil::getVar('SiriusXtecMailer', 'enabled');

        if ($enabled == 0) {
            // Add processed flag
            //$args['processed'] = 1;
            //$result = ModUtil::apiFunc('Mailer', 'user', 'sendmessage', $args);
            //return $result;
            return false;
        }

        $idApp = ModUtil::getVar('SiriusXtecMailer', 'idApp');
        $replyAddress = ModUtil::getVar('SiriusXtecMailer', 'replyAddress');
        $sender = ModUtil::getVar('SiriusXtecMailer', 'sender');
        $environment = ModUtil::getVar('SiriusXtecMailer','environment');
        $log = ModUtil::getVar('SiriusXtecMailer', 'log');
        $debug = ModUtil::getVar('SiriusXtecMailer', 'debug');
        $logpath = ModUtil::getVar('SiriusXtecMailer', 'logpath');

        $mail = new mailsender($idApp, $replyAddress, $sender, $environment, $log, $debug, $logpath);

        // add body content type
        $contenttypes = ModUtil::func('SiriusXtecMailer', 'admin', 'getContentTypes');

        // set HTML mail if required
        if (isset($args['html']) && is_bool($args['html'])) {
            if ($args['html']) {
                $bodyType = 'text/html';
            } else {
                $bodyType = TEXTPLAIN;
            }
        } else {
            $bodyType = $contenttypes[ModUtil::getVar('SiriusXtecMailer', 'contenttype')];
        }

        $message = new message($bodyType, $log, $debug, $logpath);

        // add any to addresses
        if (is_array($args['toaddress'])) {
            foreach ($args['toaddress'] as $to) {
                $message->set_to($to);
            }
        } else {
            // $toaddress is not an array -> old logic
            // process multiple names entered in a single field separated by commas (#262)
            foreach (explode(',', $args['toaddress']) as $to) {
                $message->set_to($to);
            }
        }

        // add any cc addresses
        if (isset($args['cc']) && is_array($args['cc'])) {
            foreach ($args['cc'] as $cc) {
                $message->set_cc($cc['address']);
            }
        }

        // add any bcc addresses
        if (isset($args['bcc']) && is_array($args['bcc'])) {
            foreach ($args['bcc'] as $bcc) {
                $message->set_bcc($bcc['address']);
            }
        }

        // add message subject and body
        $subject = $args['subject'];
        $message->set_subject($subject);
        $body = $args['body'];
        $message->set_bodyContent($body);

        // add attachments
        if (isset($args['attachments']) && !empty($args['attachments'])) {
            foreach ($args['attachments'] as $attachment) {
                if (is_array($attachment)) {
                    if (count($attachment) != 4) {
                        // skip invalid arrays
                        continue;
                    }
                    $message->set_attachByPathOnAppServer($attachment[1], $attachment[0]);
                } else {
                    $message->set_attachByPathOnAppServer(basename($attachment[0]), $attachment[0]);
                }
            }
        }

        // add string attachments.
        if (isset($args['stringattachments']) && !empty($args['stringattachments'])) {
            foreach ($args['stringattachments'] as $attachment) {
                if (is_array($attachment) && count($attachment) == 4) {
                    $message->set_attachByContent($attachment[1], $attachment[0], $attachment[3]);
                }
            }
        }

        // add embedded images
        if (isset($args['embeddedimages']) && !empty($args['embeddedimages'])) {
            foreach ($args['embeddedimages'] as $embeddedimage) {
                $message->set_attachByPathOnAppServer(basename($embeddedimage), $embeddedimage);
            }
        }

        //add message to mailsender
        if (!$mail->add($message)) {
            // message not added
            return LogUtil::registerError(__f('Error! A problem occurred while adding an e-mail message to \'%1$s\' (%2$s) with subject \'%3$s\'', array($args['toname'], $args['toaddress'][0], $args['subject'])));
        }

        // send message
        if (!$mail->send_mail()) {
            // message not sent
            return LogUtil::registerError(__f('Error! A problem occurred while sending an e-mail message to \'%1$s\' (%2$s) with subject \'%3$s\'', array($args['toname'], $args['toaddress'][0], $args['subject'])));
        }
		$event->stop();
		$event->setData(true);
        return true; // message sent    
    }