sendmessage_example.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. require_once __DIR__.'/../vendor/autoload.php';
  20. $conf = array(
  21. 'server' => 'talk.google.com',
  22. 'port' => 5222,
  23. 'username' => 'username',
  24. 'password' => 'password',
  25. 'proto' => 'xmpphp',
  26. 'domain' => 'gmail.com',
  27. 'printlog' => true,
  28. 'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
  29. );
  30. // Easy and simple for access to variables with their names
  31. extract($conf);
  32. $XMPP = new XMPPHP\XMPP($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel);
  33. try {
  34. $XMPP->connect();
  35. $XMPP->processUntil('session_start', 10);
  36. $XMPP->presence();
  37. $XMPP->message('target.user@jabber.domain.com', 'Hello, how are you?', 'chat');
  38. $XMPP->disconnect();
  39. } catch (XMPPHP\Exception $e) {
  40. die($e->getMessage());
  41. }