给用户发送邮件
@param string $to 收件箱
@param string $subject 标题
@param string $view 视图
@param array $params 参数
@return boolean
327437
public function sendMail($to, $subject, $view, $params = []): bool
    {
        if (empty($to)) {
            return false;
        }
        /** @var \yii\mail\MailerInterface $mailer */
        $mailer = $this->getMailer();
        return $mailer->compose(['html' => $view, 'text' => $view], $params)->setTo($to)->setSubject($subject)->send();
    }
468230
protected function includeView($view, array $vars = [], $return_content = false)
    {
        $view_file = $this->directory . $view . '.php';

        if (!$file = realpath($view_file)) {
            throw new \Exception('View file "' . $view_file . '" not exist!');
        }

        // 安全性检查，视图文件必须在视图目录下
        if (strpos($file, $this->directory) !== 0) {
            throw new \Exception('Invalid view file "' . $file . '"');
        }

        $this->included_view[$view] = true;

        $vars = $vars ? array_merge($this->vars, $vars) : $this->vars;

        $level = ob_get_level();
        ob_start();

        try {
            extract($vars);
            require $file;
        } finally {
            while (ob_get_level() > $level + 1) {
                ob_end_clean();
            }
        }

        $output = ob_get_clean();

        if ($return_content) {
            return $output;
        }

        echo $output;
    }
818879
public function send($to, $subject, $message, $from = 'default', $headerExtra = [], $html = true) {
        if (!is_null($this->method)) { // if a method is set then use that one
            if (is_string($this->method) && ('swift' == $this->method)) {
                return $this->_swiftMail($to, is_string($from) ? $this->from[$from] : $from, $subject, $message, [], $html);
            } else {
                return call_user_func($this->method, $to, is_string($from) ? $this->from[$from] : $from, $subject, $message, [], $headerExtra, $html);
            }
        } // if not use default
        return $this->_mail($to, is_string($from) ? $this->from[$from] : $from, $subject, $message, [], $headerExtra, $html);
    }
1172624
public function sendPresence($to, $from = NULL, $type = NULL) {
		$type = is_null($type) ? '' : " type=\"{$type}\"";
		return $this->send('<presence to="' . htmlspecialchars($to) . '" from="' . (is_null($from) ? $this->component_name : htmlspecialchars("$from@{$this->component_name}")) . '"' . $type . ' />');
	}
419993
protected function matches($subject, array $arguments)
    {
        if (!$this->isRestViewObject($subject)) {
            $this->exception = new FailureException(sprintf(
                'Expected %s to be an instance of FOS\RestBundle\View\View',
                $this->presenter->presentValue($subject)
            ));

            return false;
        }
        /** @var View $subject */

        $argument = isset($arguments[0]) ? $arguments[0] : [];

        if (!$this->dataMatches($subject, $argument)) {
            $this->exception = new FailureException(sprintf(
                'Expected %s to be a data of the View, but it is not. Instead got: %s',
                $this->presenter->presentValue($argument['data']),
                $this->presenter->presentValue($subject->getData())
            ));

            return false;
        }

        if (!$this->statusCodeMatches($subject, $argument)) {
            $this->exception = new FailureException(sprintf(
                'Expected %s to be a status code of the View, but it is not. Instead got: %s',
                $this->presenter->presentValue($argument['statusCode']),
                $this->presenter->presentValue($subject->getStatusCode())
            ));

            return false;
        }

        if (!$this->headersMatches($subject, $argument)) {
            $this->exception = new FailureException(sprintf(
                'Expected headers to be %s, but it is not. Instead got: %s. Details: %s',
                $this->presenter->presentValue($argument['headers']),
                $this->presenter->presentValue($subject->getHeaders()),
                $this->matcher->getError()
            ));

            return false;
        }

        if (!$this->serializationGroupsMatches($subject, $argument)) {
            $this->exception = new FailureException(sprintf(
                'Expected serialization group to be %s, but they are not',
                empty($argument['serializationGroups']) ? 'empty (it\'s impossible!)' : implode(', ', $argument['serializationGroups'])
            ));

            return false;
        }
    }
1299835
public function message($to, $message, $mediaUrls = null, array $params = [])
    {
        $params['body'] = $message;

        if (!isset($params['from'])) {
            $params['from'] = $this->from;
        }

        if (!empty($mediaUrls)) {
            $params['mediaUrl'] = $mediaUrls;
        }

        return $this->getTwilio()->messages->create($to, $params);
    }
1149267
public function send( $to, $subject, $body )
	{
		// Debug advice:
		if ( \Sifo\Domains::getInstance()->getDebugMode() )
		{
			$this->_dispatchMailController( $to, $subject, $body );
		}
		return parent::send( $to, $subject, $body );
	}
1177538
public function render($view, array $params = array())
    {
        $this->setView($view);
        $this->setParams( array_merge($this->getDefaultViewParams(), $params) );
        $this->setOutput( $this->twig->render($this->getView(), $this->getParams()) );
        return $this->getOutput();
    }
900406
public static function routeParse($from, $to, $url)
    {
        // validation and parse route pattern
        $result = preg_match('/^(\(([^\)]+)\)|[^\/]*)(.*)/', $from, $data);

        if ($result !== 1) {
            return false;
        }

        // prepare patter to test url and replacement
        $pattern = '/^' . str_replace('/', '\/', $data[3]) . '$/';

        // test route pattern match
        $result = preg_match($pattern, $url);

        if ($result !== 1) {
            return false;
        }

        // create RouteInfo object and fill fields
        $route = new RouteInfo();
        // make array of supported methods
        $route->methods = empty($data[2]) ? [] : explode('|', $data[2]);
        // replace pattern url
        $route->url = preg_replace($pattern, $to, $url);

        return $route;
    }
789445
public static function mail($text, $subject = null, $to = null)
    {
        if (!self::isDebug()) {
            return false;
        }

        $_this = self::i();

        if (empty($subject)) {
            $subject = self::$_config['mail']['subject'];
        }

        if (empty($to)) {
            $to = isset(self::$_config['mail']['to'])
                ? self::$_config['mail']['to']
                : 'jbdump@' . $_SERVER['HTTP_HOST'];
        }

        if (is_array($to)) {
            $to = implode(', ', $to);
        }

        // message
        $message   = array();
        $message[] = '<html><body>';
        $message[] = '<p><b>JBDump mail from '
            . '<a href="http://' . $_SERVER['HTTP_HOST'] . '">' . $_SERVER['HTTP_HOST'] . '</a>'
            . '</b></p>';

        $message[] = '<p><b>Date</b>: ' . date(DATE_RFC822, time()) . '</p>';
        $message[] = '<p><b>IP</b>: ' . self::getClientIP() . '</p>';
        $message[] = '<b>Debug message</b>: <pre>' . print_r($text, true) . '</pre>';
        $message[] = '</body></html>';
        $message   = wordwrap(implode(PHP_EOL, $message), 70);

        // To send HTML mail, the Content-type header must be set
        $headers   = array();
        $headers[] = 'MIME-Version: 1.0';
        $headers[] = 'Content-type: text/html; charset=utf-8';
        $headers[] = 'To: ' . $to;
        $headers[] = 'From: JBDump debug <jbdump@' . $_SERVER['HTTP_HOST'] . '>';
        $headers[] = 'X-Mailer: JBDump v' . self::VERSION;
        $headers   = implode("\r\n", $headers);

        $result = mail($to, $subject, $message, $headers);
        if (self::$_config['mail']['log']) {
            $_this->log(
                array(
                    'email'   => $to,
                    'subject' => $subject,
                    'message' => $message,
                    'headers' => $headers,
                    'result'  => $result
                ),
                'JBDump::mail'
            );
        }

        return $result;
    }
222267
public static function replaceString($from, $to, $subject, $limit = 100000)
    {
        $from = '/' . preg_quote($from, '/') . '/';
        return preg_replace($from, $to, $subject, $limit);
    }
331474
public function url($to = null, $scope = 'snsapi_userinfo', $state = 'STATE')
    {
        $to !== null || $to = Url::current();

        $queryStr = [
            'appid'         => $this->getAppId(),
            'redirect_uri'  => $to,
            'response_type' => 'code',
            'scope'         => $scope,
            'state'         => $state,
        ];

        return self::API_URL . '?' . http_build_query($queryStr) . '#wechat_redirect';
    }
1344110
public static function send(string $to, string $subject, string $view, array $viewVars = [], $builder = null, $from = 'default')
    {
        $message = static::createMessage($to, $subject, $from);
        if (is_callable($builder)) {
            $builder($message);
        }
        $message->setBody(static::view($view, $viewVars));

        self::getMailer()->send($message);
    }
869885
protected function sendViaEmail($source, $from, $to, $subject, $body) {
		$email = new Email($from, $to, $subject, $body);
		if($source->getDryRun()) {
			$source->log("[Skipped] Sent message to $to (subject: $subject)");
		} else {
			$email->sendPlain();
			$source->log("Sent message to $to (subject: $subject)");
		}
	}
1078671
public function send($touser, $template_id, $url, $topcolor, array $data, $miniprogram = NUll)
    {
        /**
         * {
         * "touser":"OPENID",
         * "template_id":"ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY",
         * "url":"http://weixin.qq.com/download",
         * "miniprogram":{
         * "appid":"xiaochengxuappid12345",
         * "pagepath":"index?foo=bar"
         * },
         * "topcolor":"#FF0000",
         * "data":{
         * "first": {
         * "value":"您好，您已成功消费。",
         * "color":"#0A0A0A"
         * },
         * "keynote1":{
         * "value":"海记汕头牛肉",
         * "color":"#CCCCCC"
         * },
         * "keynote2": {
         * "value":"8703514836",
         * "color":"#CCCCCC"
         * },
         * "keynote3":{
         * "value":"2014-08-03 19:35",
         * "color":"#CCCCCC"
         * },
         * "remark":{
         * "value":"欢迎再次购买。",
         * "color":"#173177"
         * }
         * }
         */
        $params = array();
        $params['touser'] = $touser;
        $params['template_id'] = $template_id;
        $params['url'] = $url;
        if (! is_null($miniprogram)) {
            $params['miniprogram'] = $miniprogram;
        }
        $params['topcolor'] = $topcolor;
        $params['data'] = $data;
        $rst = $this->_request->post($this->_url . 'message/template/send', $params);
        return $this->_client->rst($rst);
    }
814578
function hasActionParameter( $parameterName, $view = '' )
    {
        if ( $view == '' )
            $view = self::currentView();
        if ( isset( $this->ViewActionParameters[$view][$parameterName] ) )
            return true;
        $currentAction = $this->currentAction( $view );
        $http = eZHTTPTool::instance();
        if ( isset( $this->Functions[$view]['post_action_parameters'][$currentAction] ) )
        {
            $postParameters = $this->Functions[$view]['post_action_parameters'][$currentAction];
            if ( isset( $postParameters[$parameterName] ) and
                 $http->hasPostVariable( $postParameters[$parameterName] ) )
            {
                return true;
            }
        }
        if ( isset( $this->Functions[$view]['post_value_action_parameters'][$currentAction] ) )
        {
            $postParameters = $this->Functions[$view]['post_value_action_parameters'][$currentAction];
            if ( isset( $postParameters[$parameterName] ) )
            {
                $postVariables = $http->attribute( 'post' );
                $postVariableNameMatch = $postParameters[$parameterName];
                $regMatch = "/^" . $postVariableNameMatch . "_(.+)$/";
                foreach ( $postVariables as $postVariableName => $postVariableValue )
                {
                    if ( preg_match( $regMatch, $postVariableName, $matches ) )
                    {
                        $parameterValue = $matches[1];
                        $this->ViewActionParameters[$view][$parameterName] = $parameterValue;
                        return true;
                    }
                }
            }
        }
        return false;
    }
1308561
public static function getHtmlMail($mailView, $params, $to, $from, $subject) {
        if (file_exists($mailView)) {
            ob_start();
            require_once $mailView;
            $body = ob_get_contents();
            ob_end_clean();
        } else {
            throw new MailViewException($mailView);
        }

        $mail = new MailMessage($to, $from, $body, $subject);
        $headers = "MIME-Version: 1.0\r\n"
                . "Content-Type: text/html; charset=utf-8\r\n"
                . "Content-Transfer-Encoding: 8bit\r\n"
                . "From: =?UTF-8?B?" . base64_encode($params["from_name"]) . "?= <" . $from . ">\r\n"
                . "X-Mailer: PHP/" . phpversion();
        $mail->setHeaders($headers);
        return $mail;
    }