sendmessage_example.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @file: XMPPHP Send message example
  4. *
  5. * @info: If this script doesn't work, are you running 64-bit PHP with < 5.2.6?
  6. */
  7. /**
  8. * Activate full error reporting
  9. * error_reporting(E_ALL & E_STRICT);
  10. *
  11. * XMPPHP Log levels:
  12. *
  13. * LEVEL_ERROR = 0;
  14. * LEVEL_WARNING = 1;
  15. * LEVEL_INFO = 2;
  16. * LEVEL_DEBUG = 3;
  17. * LEVEL_VERBOSE = 4;
  18. */
  19. $conf = [
  20. 'server' => 'jabber.domain.com',
  21. 'port' => 5222,
  22. 'username' => 'username',
  23. 'password' => 'password',
  24. 'proto' => 'xmpphp',
  25. 'domain' => 'domain.net',
  26. 'printlog' => true,
  27. 'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
  28. ];
  29. // Easy and simple for access to variables with their names
  30. extract($conf);
  31. $XMPP = new XMPPHP\XMPP($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel);
  32. try {
  33. $XMPP->connect();
  34. $XMPP->processUntil('session_start', 10);
  35. $XMPP->presence();
  36. $XMPP->message('target.user@jabber.domain.com', 'Hello, how are you?', 'chat');
  37. $XMPP->disconnect();
  38. } catch (XMPPHP\Exception $e) {
  39. die($e->getMessage());
  40. }