Published message to given exchange.

@param string $body
@param array $headers
@param string $exchange
@param string $routingKey
@param bool $mandatory
@param bool $immediate
@return bool|PromiseInterface|int
162046
public function publish($body, array $headers = [], $exchange = '', $routingKey = '', $mandatory = false, $immediate = false)
    {
        $response = $this->publishImpl($body, $headers, $exchange, $routingKey, $mandatory, $immediate);

        if ($this->mode === ChannelModeEnum::CONFIRM) {
            if ($response instanceof PromiseInterface) {
                return $response->then(function () {
                    return ++$this->deliveryTag;
                });
            } else {
                return ++$this->deliveryTag;
            }
        } else {
            return $response;
        }
    }
356030
public function addRequest($messageBody, $server, $requestId, $routingKey = '')
    {
        if (empty($requestId)) {
            throw new \InvalidArgumentException("You must provide a request ID");
        }
        $this->setParameter('correlation_id', $requestId);
        $this->setParameter('reply_to', $this->queueName);

        $message = new AMQPMessage(
            $messageBody,
            $this->getParameters()
        );

        $this->channel
            ->basic_publish($message, $server . '-exchange', $routingKey);

        $this->requests++;
    }
502598
protected function MailSend($header, $body) {
    $toArr = array();
    foreach($this->to as $t) {
      $toArr[] = $this->AddrFormat($t);
    }
    $to = implode(', ', $toArr);

    if (empty($this->Sender)) {
      $params = "-oi ";
    } else {
      $params = sprintf("-oi -f%s", $this->Sender);
    }
    if ($this->Sender != '' and !ini_get('safe_mode')) {
      $old_from = ini_get('sendmail_from');
      ini_set('sendmail_from', $this->Sender);
    }
    if ($this->SingleTo === true && count($toArr) > 1) {
      foreach ($toArr as $key => $val) {
        $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params);
        // implement call back function if it exists
        $isSent = ($rt == 1) ? 1 : 0;
        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
      }
    } else {
      $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params);
      // implement call back function if it exists
      $isSent = ($rt == 1) ? 1 : 0;
      $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
    }
    if (isset($old_from)) {
      ini_set('sendmail_from', $old_from);
    }
    if(!$rt) {
      throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
    }
    return true;
  }
1012497
public function send($to, $subject, $body, $headers)
    {
        return mail(
            $to,
            $subject,
            $body,
            $headers
        );
    }
891582
protected function makeHttpRequest($url, $method, $headers, $body = null) {
    $request_headers = array_merge($headers, self::$api_version_header);

    $result = $this->doHttpRequest($url,
                                   $method,
                                   $request_headers,
                                   $body);

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

    return [
      'status_code' => $result['status_code'],
      'headers' => $result['headers'],
      'body' => $result['body'],
    ];
  }
897519
public function publishMessage($exchangeName, $routingKey, $message)
    {
        $informations = $this->query('POST', sprintf(
            '/api/exchanges/%s/%s/publish',
            $this->credentials['vhost'],
            $exchangeName
        ), array(
            'properties'       => array(),
            'routing_key'      => $routingKey,
            'payload'          => $message,
            'payload_encoding' => 'string',
        ));

        $decodedInformations = json_decode($informations, true);

        if (isset($decodedInformations['routed']) && true === $decodedInformations['routed']) {
            return;
        }

        throw new \RuntimeException('Unable to send that message into rabbit.');
    }
832838
public function send($exchange, $routing_key, $message, $type = self::TYPE_TOPIC)
    {
        $message = $this->prepareMessage($message);
        if ($type == self::TYPE_TOPIC) {
            $this->channel->exchange_declare($exchange, $type, false, true, false);
        }
        $this->channel->basic_publish($message, $exchange, $routing_key);
    }
59239
protected function determineRequestSignature(
        UriInterface $uri,
        string $method,
        string $body,
        array $headers
    ): string {
        $dataToSign =
            $method . self::REQUEST_METHOD_PATH_SEPARATOR . $this->getPathWithQuery($uri) .
            $this->determineHeaderStringForSignedRequest($headers) .
            self::NEWLINE . self::NEWLINE .
            $body;

        return $this->privateKey->sign($dataToSign);
    }
1090703
public function executeSending( $subject, $body, $subscriber )
    {
        $email = $subscriber->attribute( 'email' );
        $parameters = array();
        $parameters['content_type'] = $this->emailContentType;
        $parameters['from'] = $this->emailFrom;
        $transport = eZNotificationTransport::instance( 'ezmail' );
        $result = $transport->send( array( $email ), $subject, $body, null, $parameters );
        if ( $result === false )
        {
            throw new Exception( 'Send email error! Subscriber id:' .$subscriber->attribute( 'id' ) );
        }
        eZDebugSetting::writeNotice( 'extension-ezcomments', "An email has been sent to '$email' (subject: $subject)", __METHOD__ );
    }
149257
protected function sendRequest($headers, $body)
    {
        $request = new Request(
            'POST',
            $this->ionicPushEndPoint,
            $headers,
            $body
        );
        $client = new Client();

        try {
            $response = $client->send($request);
            return $response;
        } catch (ClientException $e) {
            switch ($e->getCode()) {
                case 401:
                case 403: {
                    throw new PermissionDeniedException(
                        "Permission denied sending push", $e->getCode(), $e
                    );
                }
                case 400: {
                    throw new BadRequestException(
                        "Bad request sending push", 400, $e
                    );
                }
            }
        } catch (\Exception $e) {
            throw new RequestException(
                "An error occurred when sending push request with message: {$e->getMessage()}",
                $e->getCode(),
                $e
            );
        }

        return null;
    }
191803
public function send($subject, $body, array $users, $from = null, array $extra = array(), $force = false)
    {
        if ($this->isMailerAvailable()) {
            $body = $this->parseBodyUrl($body);

            $to = [];

            $layout = $this->contentManager->getTranslatedContent(array('type' => 'claro_mail_layout'));
            $fromEmail = $this->getMailerFrom();
            $locale = count($users) === 1 ? $users[0]->getLocale() : $this->ch->getParameter('locale_language');

            if (!$locale) {
                $locale = $this->ch->getParameter('locale_language');
            }

            $usedLayout = $layout[$locale]['content'];
            $body = str_replace('%content%', $body, $usedLayout);
            $body = str_replace('%platform_name%', $this->ch->getParameter('name'), $body);

            if ($from) {
                $body = str_replace('%first_name%', $from->getFirstName(), $body);
                $body = str_replace('%last_name%', $from->getLastName(), $body);
            } else {
                $body = str_replace('%first_name%', $this->ch->getParameter('name'), $body);
                $body = str_replace('%last_name%', '', $body);
            }

            foreach ($users as $user) {
                $mail = $user->getMail();

                if ($user->isMailValidated() || $force) {
                    $to[] = $mail;
                }
            }

            if (isset($extra['to'])) {
                foreach ($extra['to'] as $mail) {
                    if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
                        $to[] = $mail;
                    }
                }
            }

            $message = \Swift_Message::newInstance()
                ->setSubject($subject)
                ->setFrom($fromEmail)
                ->setBody($body, 'text/html');

            if ($from !== null && filter_var($from->getMail(), FILTER_VALIDATE_EMAIL)) {
                $message->setReplyTo($from->getMail());
            }

            if (count($to) > 1) {
                $message->setBcc($to);
            } else {
                $message->setTo($to);
            }

            if (isset($extra['attachment'])) {
                $message->attach(\Swift_Attachment::fromPath($extra['attachment'], "application/octet-stream"));
            }

            return $this->mailer->send($message) ? true : false;
        }

        return false;
    }
244825
public function put($url, $headers = [], $body = null)
    {
        return $this->send(Method::PUT, $url, $body, $headers);
    }
764731
public function publishMessage($message, $exchange, $routing_key = '', $flags = AMQP_NOPARAM, $attributes = [])
    {
        if (!isset($this->_exchanges[$exchange])) {
            throw new InvalidKeyException(['publish message to `:1` exchange with `:2` routing_key failed: exchange is NOT exists', $exchange, $routing_key]);
        }

        try {
            $this->_exchanges[$exchange]->publish($message, $routing_key, $flags, $attributes);
        } catch (\Exception $e) {
            throw new AmqpException(['publish message to `:1` exchange with `:2` routing_key failed: `:3`', $exchange, $routing_key, $e->getMessage()]);
        }

        return $this;
    }
1287390
protected function requestRoot(array $headers, string $body)
    {
        if ($this->method !== 'POST') {
            $this->sendError(
                static::ERROR_METHOD_NOT_IMPLEMENTED,
                "Method '$this->method' is not implemented",
                'POST'
            );
        }

        $content_type = $headers['Content-Type'] ?? '';
        $content_type = static::parseContentType($content_type);
        $mime = $content_type['mime'] ?? $content_type;

        if (empty($mime) || empty(trim($body))) {
            $this->sendError(
                static::ERROR_INVALID_PAYLOAD,
                'Expecting payload'
            );
        }

        if (!in_array($mime, static::SUPPORTED_CONTENT_TYPES)) {
            $this->sendError(
                static::ERROR_UNSUPPORTED_MEDIA_TYPE,
                "Media-Type '$mime' is not supported"
            );
        }

        if (($charset = $content_type['charset'] ?? null) !== null) {
            $body = mb_convert_encoding($body, 'UTF-8', $charset);
        }

        $available = static::AVAILABLE_CONTENT_TYPES;
        $accepted = static::getAcceptedType(
            $headers['Accept'] ?? '*/*',
            $available
        );
        if ($accepted === false) {
            $message = 'Can not generate content complying to Accept header';
            $this->sendError(static::ERROR_NOT_ACCEPTABLE, $message);
        }

        try {
            $return_file = new Parser($body);
        } catch (\InvalidArgumentException $e) {
            $code = static::ERROR_INVALID_PAYLOAD;
        } catch (\DomainException $e) {
            $code = static::ERROR_INVALID_PAYLOAD;
        } catch (ParseException $e) {
            $code = static::ERROR_INVALID_PAYLOAD;
        } catch (\UnexpectedValueException $e) {
            $code = static::ERROR_INVALID_PAYLOAD;
        } catch (\Exception $e) {
            $code = static::ERROR_INTERNAL_SERVER;
        } finally {
            if (isset($code)) {
                $this->sendError($code, $e->getMessage());
            }
        }

        if ($accepted === $available['extracted']) {
            try {
                $extractor = $return_file->extract();
            } catch (\Exception $e) {
                $this->sendError(
                    static::ERROR_INTERNAL_SERVER,
                    $e->getMessage()
                );
            }

            $data = $extractor->output();

            $authorization = $this->getAuthorizedResources('GET');
            $assignments = (array_key_exists('assignments', $authorization))
                ? Models\Assignment::dump($authorization['assignments'], 'id')
                : [];
            $titles = (array_key_exists('titles', $authorization))
                ? Models\Title::dump($authorization['titles'], 'id')
                : [];

            foreach ($data['titles'] as &$title) {
                if (!in_array($title['assignment'], $assignments)) {
                    $title['assignment'] = null;
                }
                if (!in_array($title['id'], $titles)) {
                    $title['id'] = null;
                }
            }
            unset($title);
        } else {
            $data = $return_file->output();
        }

        $response = $this->prepareResponse();
        $response->headers['Content-Type'] = $accepted;
        $response->body = $data;

        return $response;
    }
407281
protected function SmtpSend($header, $body)
    {
        //require_once $this->PluginDir . 'class.smtp.php';
        $bad_rcpt = array();

        if (!$this->SmtpConnect()) {
            throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
        }
        $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
        if (!$this->smtp->Mail($smtp_from)) {
            throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
        }

        // Attempt to send attach all recipients
        foreach ($this->to as $to) {
            if (!$this->smtp->Recipient($to[0])) {
                $bad_rcpt[] = $to[0];
            }
        }
        foreach ($this->cc as $cc) {
            if (!$this->smtp->Recipient($cc[0])) {
                $bad_rcpt[] = $cc[0];
            }
        }
        foreach ($this->bcc as $bcc) {
            if (!$this->smtp->Recipient($bcc[0])) {
                $bad_rcpt[] = $bcc[0];
            }
        }
        if (count($bad_rcpt) > 0) {
            //Create error message for any bad addresses
            $badaddresses = implode(', ', $bad_rcpt);
            throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
        }
        if (!$this->smtp->Data($header . $body)) {
            throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
        }
        if ($this->SMTPKeepAlive == true) {
            $this->smtp->Reset();
        }
        return true;
    }
141363
public function post($url, $body, array $headers = [])
    {
        $request = $this->getClient()->createRequest('POST', $url, ['body' => $body]);
        $request->addHeaders($headers);

        return $this->sendRequest($request);
    }
469961
public function request($path, $body, $httpMethod = 'GET', array $headers = [], array $options = [])
	{
		$request = $this->createRequest($httpMethod, $path, $body, $headers);

		try {
			$response = $this->client->send($request, $options);
		} catch (\LogicException $e) {
			throw new \ErrorException($e->getMessage(), $e->getCode(), $e);
		} catch (\RuntimeException $e) {
			throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
		}

		$this->lastRequest  = $request;
		$this->lastResponse = $response;

		return $response;
	}