mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-28 07:46:07 +03:00
1 line
5.3 KiB
JSON
1 line
5.3 KiB
JSON
{"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) \"20130820202406.24739.21973@samples.mailgun.org\"\r\n }\r\n }\r\n }\r\n}\r\n```\r\n\r\nFor usage examples on each API endpoint, head over to our official documentation \r\npages. \r\n\r\nThis SDK includes a [Message Builder](src/Mailgun/Messages/README.md), \r\n[Batch Message](src/Mailgun/Messages/README.md) and [Opt-In Handler](src/Mailgun/Lists/README.md) component.\r\n\r\nMessage Builder allows you to quickly create the array of parameters, required \r\nto send a message, by calling a methods for each parameter.\r\nBatch Message is an extension of Message Builder, and allows you to easily send \r\na batch message job within a few seconds. The complexity of \r\nbatch messaging is eliminated! \r\n\r\nSupport and Feedback\r\n--------------------\r\n\r\nBe sure to visit the Mailgun official \r\n[documentation website](http://documentation.mailgun.com/) for additional \r\ninformation about our API. \r\n\r\nIf you find a bug, please submit the issue in Github directly. \r\n[Mailgun-PHP Issues](https://github.com/mailgun/Mailgun-PHP/issues)\r\n\r\nAs always, if you need additional assistance, drop us a note at \r\n[support@mailgun.com](mailto:support@mailgun.com).\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} |