Send XMPP Message

@param string $to
@param string $body
@param string $type
@param string $subject
482742
public function message($to, $body, $type = 'chat', $subject = null, $payload = null) {
	    if(is_null($type))
	    {
	        $type = 'chat';
	    }
	    
		$to	  = htmlspecialchars($to);
		$body	= htmlspecialchars($body);
		$subject = htmlspecialchars($subject);
		
		$out = "<message from=\"{$this->fulljid}\" to=\"$to\" type='$type'>";
		if($subject) $out .= "<subject>$subject</subject>";
		$out .= "<body>$body</body>";
		if($payload) $out .= $payload;
		$out .= "</message>";
		
		$this->send($out);
	}
240579
public function mailReviewer($to, $subject, $data)
    {
        $this->mail->send('blogify::mails.notifyReviewer', ['data' => $data], function($message) use ($to, $subject)
        {
            $message->to($to)->subject($subject);
        });
    }
1064392
public function mailPassword($to, $subject, $data)
    {
        $this->mail->send('blogify::mails.password', ['data' => $data], function($message) use ($to, $subject)
        {
            $message->to($to)->subject($subject);
        });
    }
848023
public function send($to, $subject, $message, $from = '', $cc = '', $bcc = '') 
    {
        $to = \wf\mailer\Helper::emailEncode($to);
        $from = \wf\mailer\Helper::emailEncode($from);    
        $subject = \wf\mailer\Helper::encode($subject);

        $headers = "From: {$from}\r\n";
        $headers = "To: {$to}\r\n";
        
        // 抄送
        if($cc) {
            $cc = \wf\mailer\Helper::emailEncode($cc);
            $headers .= "Cc: {$cc}\r\n";
        }
        
        // 密送
        if($bcc) {
            $bcc = \wf\mailer\Helper::emailEncode($bcc);
            $headers .= "Bcc: {$bcc}\r\n";
        }

        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "X-Mailer: Windwork\r\n";
        $headers .= "Content-type: text/html; charset=utf-8\r\n";
        $headers .= "Content-Transfer-Encoding: base64\r\n";
        
        // 内容处理
        $message = str_replace("\n\r", "\r", $message);
        $message = str_replace("\r\n", "\n", $message);
        $message = str_replace("\r", "\n", $message);
        $message = str_replace("\n", "\r\n", $message);
        $message = chunk_split(base64_encode($message));
        
        if(!mail($to, $subject, $message, $headers)) {
            throw new Exception("Mail failed: {$to} {$subject}");
        }
        
        return true;
    }
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__ );
    }
1103505
protected function sendBody($body):void
    {
        if (is_resource($body)) {
            fpassthru($body);
            fclose($body);
        }
        else {
            echo $body;
        }
    }
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)");
		}
	}
406410
public function sendHtml ($subject, $contentHTML, $to, $cc=array(), $bcc=array())
    {
        $firstErrorMsg = '';
        $lastErrorMsg  = '';

        // Try gateways in order
        foreach ($this->gateways as $gw) {
            try {
                $gw->sendHtml($subject, $contentHTML, $to, $cc, $bcc);

                // If previous function did not throw an exception, mail deportation was successfull
                return;

            } catch (\Exception $e) {
                // Sending failed, try, next gw, store error message
                if ('' === $firstErrorMsg) {
                    $firstErrorMsg = $e->getMessage();
                }
                $lastErrorMsg = $e->getMessage();
            }
        }

        // If we reach this point, we know all GWs failed
        throw new Exception("Sending email failed through all gateways (". count($this->gateways) ." configured).\n\nFirst error message: $firstErrorMsg\nLast error message: $lastErrorMsg");
    }
351608
public function send($routing_key, $message, $exchange = null, $type = Amqp::TYPE_TOPIC)
    {
        $this->amqp->send($exchange ?: $this->exchange, $routing_key, $message, $type);
    }
833491
public function send(string $to, string $subject, string $html, string $plain=null)
    {
        $this->mail->isHTML(true);
        $this->mail->Subject = $subject;
        $this->mail->Body    = $html;
        if ($plain) {
            $this->mail->AltBody = $plain;
        }
        if ($this->mail->send()) {
            return true;
        } else {
            return false;
        }
    }
857698
public function sendMail($to, $subject = '', $message = '', $headers = '')
    {
        if (empty($headers)) {
            $headers = 'From: ' . APP_SYS_EMAIL;
        }
        mail($to, $subject, $message, $headers);
    }
1013643
public function endpoint_sendmessage($to = NULL, $from = NULL, $body = NULL)
        {
            return $this->sendmessage($to, $from, $body);
        }
555520
private function _mail($to, $subject, $message)
		{
			// Set up swift mailer if needed
			if (!$this->_mailer) {
				$transport = NULL;
				// Set transport to php
				if (strtolower($this->transportType) == 'php') {
					$transport = Swift_MailTransport::newInstance();
				} // Set transport to smtp
				elseif (strtolower($this->transportType) == 'smtp') {
					$transport = \Swift_SmtpTransport::newInstance();

					foreach ($this->transportOptions as $option => $value) {
						$methodName = 'set' . ucfirst($option);
						$transport->$methodName($value);
					}
				}

				// Create Mailer object
				$this->_mailer = \Swift_Mailer::newInstance($transport);
			}

			// Set up message
			$mailer  = $this->_mailer;
			$message = Swift_Message::newInstance($subject)->setFrom('not@used.com')->setTo($to)->setBody($message);

			return $mailer->send($message);
		}
1290874
private function sendWebMessage($mes, $text, $to) {
        // Esto no haría falta :S
        $mes['text'] = $text;

        $pusher = $this->container->get('gos_web_socket.wamp.pusher');
        $pusher->push($mes, 'session_topic', ['idSession' => $to]);

        /*
        $pusher->push([
            'data' => $data,
            'text' => $text
        ], 'session_topic', ['idSession' => $to]);
        */

        return true;
    }
1300089
public function send($subject, $body, array $users, $from = null, array $extra = [], $force = false, $replyToMail = null)
    {
        $parameters = $this->serializer->serialize([Options::SERIALIZE_MINIMAL]);
        if (0 === count($users) && (!isset($extra['to']) || 0 === count($extra['to']))) {
            //obviously, if we're not going to send anything to anyone, it's better to stop
            return false;
        }

        if ($this->isMailerAvailable()) {
            $to = [];

            $fromEmail = $parameters['mailer']['from'];
            $locale = 1 === count($users) ? $users[0]->getLocale() : $parameters['locales']['default'];

            if (!$locale) {
                $locale = $parameters['locales']['default'];
            }

            $body = $this->templateManager->getTemplate('claro_mail_layout', ['content' => $body], $locale);
            $body = str_replace('%platform_name%', $parameters['display']['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%', $parameters['display']['name'], $body);
                $body = str_replace('%last_name%', '', $body);
            }

            foreach ($users as $user) {
                $email = $user->getEmail();

                if ($user->isMailValidated() || $force) {
                    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                        $to[] = $email;
                    }
                }
            }

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

            $message = new Message();
            $message->subject($subject);
            $message->from($fromEmail);
            $message->body($body);

            (null !== $from && filter_var($from->getEmail(), FILTER_VALIDATE_EMAIL)) ?
                $message->replyTo($from->getEmail()) :
                $message->replyTo($replyToMail);

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

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

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

        return false;
    }
519083
public function createMessage($subject = null, $body = null, $contentType = null, $charset = null)
    {
        $message = Swift_Message::newInstance($subject, $body, $contentType, $charset);

        if(null !== $this->fromEmail) {
            
            if(null === $this->fromName) {
                $message->setFrom($this->fromEmail);
            } else {
                $message->setFrom($this->fromEmail, $this->fromName);
            }
            
        }

        return $message;
    }
794087
public function sendMessage($recipient, $message, $notificationType = NotificationType::REGULAR, $messagingType = MessagingType::RESPONSE)
    {
        $message = $this->createMessage($message);
        $options = RequestOptionsFactory::createForMessage($recipient, $message, $notificationType, $messagingType);
        $response = $this->client->send('POST', '/me/messages', null, [], [], $options);
        $responseData = $this->decodeResponse($response);

        return new MessageResponse($responseData['recipient_id'], $responseData['message_id']);
    }