mailgun-php/params.json

1 line
5.3 KiB
JSON
Raw Permalink Normal View History

2013-09-12 23:07:04 +04:00
{"name":"mailgun-php","tagline":"Official Mailgun PHP SDK","body":"Mailgun-PHP\r\n===========\r\n\r\nThis is the Mailgun PHP SDK. This SDK contains methods for easily interacting \r\nwith the Mailgun API. \r\nBelow are examples to get you started. For additional examples, please see our \r\nofficial documentation \r\nat http://documentation.mailgun.com\r\n\r\n[![Latest Stable Version](https://poser.pugx.org/mailgun/mailgun-php/v/stable.png)](https://packagist.org/packages/mailgun/mailgun-php)\r\n[![Build Status](https://travis-ci.org/mailgun/mailgun-php.png)](https://travis-ci.org/mailgun/mailgun-php)\r\n\r\nInstallation\r\n------------\r\nTo install the SDK, you will need to be using [Composer](http://getcomposer.org/) \r\nin your project. \r\nIf you aren't using Composer yet, it's really simple! Here's how to install \r\ncomposer and the Mailgun SDK.\r\n\r\n```PHP\r\n# Install Composer\r\ncurl -sS https://getcomposer.org/installer | php\r\n\r\n# Add Mailgun as a dependency\r\nphp composer.phar require mailgun/mailgun-php:~1.2\r\n``` \r\n\r\nFor shared hosts with SSH access, you might need to run this instead (contact \r\nyour shared host for assistance): \r\n```\r\nphp -d detect_unicode=Off -r \"eval('?>'.file_get_contents('https://getcomposer.org/installer'));\"\r\n```\r\n\r\nNext, require Composer's autoloader, in your application, to automatically \r\nload the Mailgun SDK in your project:\r\n```PHP\r\nrequire 'vendor/autoload.php';\r\nuse Mailgun\\Mailgun;\r\n```\r\n\r\nUsage\r\n-----\r\nHere's how to send a message using the SDK:\r\n\r\n```php\r\n# First, instantiate the SDK with your API credentials and define your domain. \r\n$mg = new Mailgun(\"key-example\");\r\n$domain = \"example.com\";\r\n\r\n# Now, compose and send your message.\r\n$mg->sendMessage($domain, array('from' => 'bob@example.com', \r\n 'to' => 'sally@example.com', \r\n 'subject' => 'The PHP SDK is awesome!', \r\n 'text' => 'It is so simple to send a message.'));\r\n```\r\n\r\nOr obtain the last 25 log items: \r\n```php\r\n# First, instantiate the SDK with your API credentials and define your domain. \r\n$mg = new Mailgun(\"key-example\");\r\n$domain = \"example.com\";\r\n\r\n# Now, issue a GET against the Logs endpoint.\r\n$mg->get(\"$domain/log\", array('limit' => 25, \r\n 'skip' => 0));\r\n```\r\n\r\nResponse\r\n--------\r\n\r\nThe results, provided by the endpoint, are returned as an object, which you \r\ncan traverse like an array. \r\n\r\nExample: \r\n\r\n```php\r\n$mg = new Mailgun(\"key-example\");\r\n$domain = \"example.com\";\r\n\r\n$result = $mg->get(\"$domain/log\", array('limit' => 25, \r\n 'skip' => 0));\r\n\r\n$httpResponseCode = $result->http_response_code;\r\n$httpResponseBody = $result->http_response_body;\r\n\r\n# Iterate through the results and echo the message IDs.\r\n$logItems = $result->http_response_body->items;\r\nforeach($logItems as $logItem){\r\n echo $logItem->message_id . \"\\n\";\r\n}\r\n```\r\n\r\nExample Contents: \r\n**$httpResponseCode** will contain an integer. You can find how we use HTTP response \r\ncodes in our documentation: \r\nhttp://documentation.mailgun.com/api-intro.html?highlight=401#errors\r\n\r\n**$httpResponseBody** will contain an object of the API response. In the above \r\nexample, a var_dump($result) would contain the following: \r\n\r\n```\r\nobject(stdClass)#26 (2) {\r\n[\"http_response_body\"]=>\r\n object(stdClass)#26 (2) {\r\n [\"total_count\"]=>\r\n int(12)\r\n [\"items\"]=>\r\n array(1) {\r\n [0]=>\r\n object(stdClass)#31 (5) {\r\n [\"hap\"]=>\r\n string(9) \"delivered\"\r\n [\"created_at\"]=>\r\n string(29) \"Tue, 20 Aug 2013 20:24:34 GMT\"\r\n [\"message\"]=>\r\n string(66) \"Delivered: me@samples.mailgun.org → travis@mailgunhq.com 'Hello'\"\r\n [\"type\"]=>\r\n string(4) \"info\"\r\n [\"message_id\"]=>\r\n string(46