Skip to content

Instantly share code, notes, and snippets.

@DavidGarciaCat
Created January 17, 2018 14:20
Show Gist options
  • Select an option

  • Save DavidGarciaCat/acbf2141b62bdd3bfe3ddff8cafe31e9 to your computer and use it in GitHub Desktop.

Select an option

Save DavidGarciaCat/acbf2141b62bdd3bfe3ddff8cafe31e9 to your computer and use it in GitHub Desktop.
{
"require": {
"mailgun/mailgun-php": "^2.4",
"php-http/curl-client": "^1.7",
"guzzlehttp/psr7": "^1.4"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "6ceb9d9e92fead3aec67ac3929c352eb",
"packages": [
{
"name": "clue/stream-filter",
"version": "v1.4.0",
"source": {
"type": "git",
"url": "https://github.com/clue/php-stream-filter.git",
"reference": "d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/clue/php-stream-filter/zipball/d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0",
"reference": "d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0",
"shasum": ""
},
"require": {
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "^5.0 || ^4.8"
},
"type": "library",
"autoload": {
"psr-4": {
"Clue\\StreamFilter\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Christian Lück",
"email": "[email protected]"
}
],
"description": "A simple and modern approach to stream filtering in PHP",
"homepage": "https://github.com/clue/php-stream-filter",
"keywords": [
"bucket brigade",
"callback",
"filter",
"php_user_filter",
"stream",
"stream_filter_append",
"stream_filter_register"
],
"time": "2017-08-18T09:54:01+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "[email protected]",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "mailgun/mailgun-php",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/mailgun/mailgun-php.git",
"reference": "20783215042b181b0dec92c9e01947b93cb5d085"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mailgun/mailgun-php/zipball/20783215042b181b0dec92c9e01947b93cb5d085",
"reference": "20783215042b181b0dec92c9e01947b93cb5d085",
"shasum": ""
},
"require": {
"php": "^5.5|^7.0",
"php-http/client-common": "^1.1",
"php-http/discovery": "^1.0",
"php-http/httplug": "^1.0",
"php-http/message": "^1.0",
"php-http/multipart-stream-builder": "^1.0",
"webmozart/assert": "^1.2"
},
"require-dev": {
"guzzlehttp/psr7": "^1.4",
"php-http/guzzle6-adapter": "^1.0",
"phpunit/phpunit": "~4.8"
},
"type": "library",
"autoload": {
"psr-0": {
"Mailgun": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Travis Swientek",
"email": "[email protected]"
}
],
"description": "The Mailgun SDK provides methods for all API functions.",
"time": "2017-12-07T21:05:43+00:00"
},
{
"name": "php-http/client-common",
"version": "1.7.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/client-common.git",
"reference": "9accb4a082eb06403747c0ffd444112eda41a0fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/client-common/zipball/9accb4a082eb06403747c0ffd444112eda41a0fd",
"reference": "9accb4a082eb06403747c0ffd444112eda41a0fd",
"shasum": ""
},
"require": {
"php": "^5.4 || ^7.0",
"php-http/httplug": "^1.1",
"php-http/message": "^1.6",
"php-http/message-factory": "^1.0",
"symfony/options-resolver": "^2.6 || ^3.0 || ^4.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.4",
"phpspec/phpspec": "^2.5 || ^3.4 || ^4.2"
},
"suggest": {
"php-http/cache-plugin": "PSR-6 Cache plugin",
"php-http/logger-plugin": "PSR-3 Logger plugin",
"php-http/stopwatch-plugin": "Symfony Stopwatch plugin"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Client\\Common\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
}
],
"description": "Common HTTP Client implementations and tools for HTTPlug",
"homepage": "http://httplug.io",
"keywords": [
"client",
"common",
"http",
"httplug"
],
"time": "2017-11-30T11:06:59+00:00"
},
{
"name": "php-http/curl-client",
"version": "v1.7.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/curl-client.git",
"reference": "0972ad0d7d37032a52077a5cbe27cf370f2007d8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/curl-client/zipball/0972ad0d7d37032a52077a5cbe27cf370f2007d8",
"reference": "0972ad0d7d37032a52077a5cbe27cf370f2007d8",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": "^5.5 || ^7.0",
"php-http/discovery": "^1.0",
"php-http/httplug": "^1.0",
"php-http/message": "^1.2",
"php-http/message-factory": "^1.0.2"
},
"provide": {
"php-http/async-client-implementation": "1.0",
"php-http/client-implementation": "1.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.0",
"php-http/client-integration-tests": "^0.5.1",
"phpunit/phpunit": "^4.8.27",
"zendframework/zend-diactoros": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Http\\Client\\Curl\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Михаил Красильников",
"email": "[email protected]"
}
],
"description": "cURL client for PHP-HTTP",
"homepage": "http://php-http.org",
"keywords": [
"curl",
"http"
],
"time": "2017-02-09T15:18:33+00:00"
},
{
"name": "php-http/discovery",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/discovery.git",
"reference": "7b50ab4d6c9fdaa1ed53ae310c955900af6e3372"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/discovery/zipball/7b50ab4d6c9fdaa1ed53ae310c955900af6e3372",
"reference": "7b50ab4d6c9fdaa1ed53ae310c955900af6e3372",
"shasum": ""
},
"require": {
"php": "^5.5 || ^7.0"
},
"require-dev": {
"henrikbjorn/phpspec-code-coverage": "^2.0.2",
"php-http/httplug": "^1.0",
"php-http/message-factory": "^1.0",
"phpspec/phpspec": "^2.4",
"puli/composer-plugin": "1.0.0-beta10"
},
"suggest": {
"php-http/message": "Allow to use Guzzle, Diactoros or Slim Framework factories",
"puli/composer-plugin": "Sets up Puli which is recommended for Discovery to work. Check http://docs.php-http.org/en/latest/discovery.html for more details."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Discovery\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
}
],
"description": "Finds installed HTTPlug implementations and PSR-7 message factories",
"homepage": "http://php-http.org",
"keywords": [
"adapter",
"client",
"discovery",
"factory",
"http",
"message",
"psr7"
],
"time": "2017-08-03T10:12:53+00:00"
},
{
"name": "php-http/httplug",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/httplug.git",
"reference": "1c6381726c18579c4ca2ef1ec1498fdae8bdf018"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/httplug/zipball/1c6381726c18579c4ca2ef1ec1498fdae8bdf018",
"reference": "1c6381726c18579c4ca2ef1ec1498fdae8bdf018",
"shasum": ""
},
"require": {
"php": ">=5.4",
"php-http/promise": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"henrikbjorn/phpspec-code-coverage": "^1.0",
"phpspec/phpspec": "^2.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Eric GELOEN",
"email": "[email protected]"
},
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
}
],
"description": "HTTPlug, the HTTP client abstraction for PHP",
"homepage": "http://httplug.io",
"keywords": [
"client",
"http"
],
"time": "2016-08-31T08:30:17+00:00"
},
{
"name": "php-http/message",
"version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/message.git",
"reference": "2edd63bae5f52f79363c5f18904b05ce3a4b7253"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/message/zipball/2edd63bae5f52f79363c5f18904b05ce3a4b7253",
"reference": "2edd63bae5f52f79363c5f18904b05ce3a4b7253",
"shasum": ""
},
"require": {
"clue/stream-filter": "^1.3",
"php": ">=5.4",
"php-http/message-factory": "^1.0.2",
"psr/http-message": "^1.0"
},
"provide": {
"php-http/message-factory-implementation": "1.0"
},
"require-dev": {
"akeneo/phpspec-skip-example-extension": "^1.0",
"coduo/phpspec-data-provider-extension": "^1.0",
"ext-zlib": "*",
"guzzlehttp/psr7": "^1.0",
"henrikbjorn/phpspec-code-coverage": "^1.0",
"phpspec/phpspec": "^2.4",
"slim/slim": "^3.0",
"zendframework/zend-diactoros": "^1.0"
},
"suggest": {
"ext-zlib": "Used with compressor/decompressor streams",
"guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories",
"slim/slim": "Used with Slim Framework PSR-7 implementation",
"zendframework/zend-diactoros": "Used with Diactoros Factories"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.6-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Message\\": "src/"
},
"files": [
"src/filters.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
}
],
"description": "HTTP Message related tools",
"homepage": "http://php-http.org",
"keywords": [
"http",
"message",
"psr-7"
],
"time": "2017-07-05T06:40:53+00:00"
},
{
"name": "php-http/message-factory",
"version": "v1.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-http/message-factory.git",
"reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/message-factory/zipball/a478cb11f66a6ac48d8954216cfed9aa06a501a1",
"reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1",
"shasum": ""
},
"require": {
"php": ">=5.4",
"psr/http-message": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
}
],
"description": "Factory interfaces for PSR-7 HTTP Message",
"homepage": "http://php-http.org",
"keywords": [
"factory",
"http",
"message",
"stream",
"uri"
],
"time": "2015-12-19T14:08:53+00:00"
},
{
"name": "php-http/multipart-stream-builder",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/multipart-stream-builder.git",
"reference": "1fa3c623fc813a43b39494b2a1612174e36e0fb0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/multipart-stream-builder/zipball/1fa3c623fc813a43b39494b2a1612174e36e0fb0",
"reference": "1fa3c623fc813a43b39494b2a1612174e36e0fb0",
"shasum": ""
},
"require": {
"php": "^5.5 || ^7.0",
"php-http/discovery": "^1.0",
"php-http/message-factory": "^1.0.2",
"psr/http-message": "^1.0"
},
"require-dev": {
"php-http/message": "^1.5",
"phpunit/phpunit": "^4.8 || ^5.4",
"zendframework/zend-diactoros": "^1.3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.3-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Message\\MultipartStream\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Tobias Nyholm",
"email": "[email protected]"
}
],
"description": "A builder class that help you create a multipart stream",
"homepage": "http://php-http.org",
"keywords": [
"factory",
"http",
"message",
"multipart stream",
"stream"
],
"time": "2017-05-21T17:45:25+00:00"
},
{
"name": "php-http/promise",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/promise.git",
"reference": "dc494cdc9d7160b9a09bd5573272195242ce7980"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/promise/zipball/dc494cdc9d7160b9a09bd5573272195242ce7980",
"reference": "dc494cdc9d7160b9a09bd5573272195242ce7980",
"shasum": ""
},
"require-dev": {
"henrikbjorn/phpspec-code-coverage": "^1.0",
"phpspec/phpspec": "^2.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Promise\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
},
{
"name": "Joel Wurtz",
"email": "[email protected]"
}
],
"description": "Promise used for asynchronous HTTP requests",
"homepage": "http://httplug.io",
"keywords": [
"promise"
],
"time": "2016-01-26T13:27:02+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "symfony/options-resolver",
"version": "v3.4.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "f31f4d3ce4eaf7597abc41bd5ba53d634c2fdb0e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/f31f4d3ce4eaf7597abc41bd5ba53d634c2fdb0e",
"reference": "f31f4d3ce4eaf7597abc41bd5ba53d634c2fdb0e",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\OptionsResolver\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony OptionsResolver Component",
"homepage": "https://symfony.com",
"keywords": [
"config",
"configuration",
"options"
],
"time": "2018-01-03T07:37:34+00:00"
},
{
"name": "webmozart/assert",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/webmozart/assert.git",
"reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f",
"reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.6",
"sebastian/version": "^1.0.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
}
},
"autoload": {
"psr-4": {
"Webmozart\\Assert\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "[email protected]"
}
],
"description": "Assertions to validate method input/output with nice error messages.",
"keywords": [
"assert",
"check",
"validate"
],
"time": "2016-11-23T20:04:58+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$params = [
'from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'MailGun email with attached files',
'text' => 'This email contains 2 attached images and 1 PDF file.',
'attachment' => [
[
'filePath' => 'attachment/php.jpg',
'filename' => 'php.jpg'
],
[
'filePath' => 'attachment/symfony.png',
'filename' => 'symfony.png'
],
[
'filePath' => 'attachment/pdf-file.pdf',
'filename' => 'pdf-file.pdf'
],
],
];
$mg = Mailgun::create('key-example');
$mg->messages()->send('domain.com', $params);
@DavidGarciaCat
Copy link
Author

DavidGarciaCat commented Jan 17, 2018

INBOX

screen shot 2018-01-17 at 14 09 48

attachment/php.jpg

php

attachment/symfony.png

symfony

attachment/pdf-file.pdf

pdf-file.pdf

@Naren-hybreeder
Copy link

Thanks for the code. I tried the same but I am getting the error. Do have any idea why I am getting this?

Fatal error: Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors - Puli Factory is not available - No valid candidate found using strategy "Http\Discovery\Strategy\CommonClassesStrategy". We tested the following candidates: . - No valid candidate found using strategy "Http\Discovery\Strategy\CommonPsr17ClassesStrategy". We tested the following candidates: Nyholm\Psr7\Factory\Psr17Factory, Zend\Diactoros\UriFactory, Http\Factory\Diactoros\UriFactory, Http\Factory\Guzzle\UriFactory, Http\Factory\Slim\UriFactory. in /opt/lampp/htdocs/mailgun-php/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php:41 Stack trace: #0 /opt/lampp/htdocs/mailgun-php/vendor/php-http/discovery/src/ClassDiscovery.php(79): Http\Discovery\Exception\DiscoveryFailedException::create(Array) #1 /opt/lampp/htdocs/mailgun-php/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php(117): in /opt/lampp/htdocs/mailgun-php/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php on line 22

@DavidGarciaCat
Copy link
Author

Do you have these 3 packages (maybe with different versions)?

    "require": {
        "mailgun/mailgun-php": "^2.4",
        "php-http/curl-client": "^1.7",
        "guzzlehttp/psr7": "^1.4"
    }

Either 2.4 and newer versions, Mailgun uses the HTTPlug integration, so you will need to require a PSR7 implementation (like guzzlehttp/psr7) and any HTTP Plug adapter or client (like php-http/curl-client).

Take a look here to check all your options, maybe there's another one that fits better for your project:

https://docs.php-http.org/en/latest/clients.html

@Naren-hybreeder
Copy link

@DavidGarciaCat, I install the latest version of composer and I got this.

composer.json

{
    "require": {
        "mailgun/mailgun-php": "^3.0",
        "php-http/guzzle6-adapter": "^2.0",
        "php-http/message": "^1.8"
    }
}

@DavidGarciaCat
Copy link
Author

Please try using a PSR7 implementation like the one that Guzzle has or maybe the one that Nyholm created (as suggested by the SDK's install section)

composer require mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7

https://github.com/mailgun/mailgun-php#installation

In your case, the Buzz client was replaced by the Guzzle Adapter (cool). However, the PSR7 implementation is missing because php-http/message vendor is not a PSR7 implementation but a set of HTTP Message related tools as described in the Repo page as well as on Packagist.

https://github.com/php-http/message#http-message

https://packagist.org/packages/php-http/message

So, the problem is the missing PSR7 implementation

@Naren-hybreeder
Copy link

Thanks for the reply.
I tried this composer require mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7 but I am getting composer: command not found

The steps which I am following for sending the email

  1. Created account in mailgun and verified my domain which done.
  2. Created one folder called mailgun-php and run below command in terminal
# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add Mailgun and Guzzle6 as a dependency (see GitHub README below for more info)
php composer.phar require mailgun/mailgun-php php-http/guzzle6-adapter php-http/message
  1. I got composer.json, composer.lock, composer.phar, and vendor in my mailgun-folder
  2. I created a test.php in mailgun-php folder and added below code

require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('myApi key');
$domain = "mydomain.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
	'from'	=> '[email protected]', // this is my registered email
	'to'	=> '[email protected]',
	'subject' => 'Hello',
	'text'	=> 'Testing some Mailgun awesomness!'
));

Now when I run may page then I am getting above erro. I need to know anything i missed ? Please help me I am first time implementing the mailgun.

@DavidGarciaCat
Copy link
Author

So, on your 2nd step...

curl -sS https://getcomposer.org/installer | php

...this creates the composer.phar that you run with the php composer.phar ... so it means that...

composer require mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7

...gives you the error because composer is not a system's binary; you can try with...

curl -sS https://getcomposer.org/installer | php
php composer.phar require mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7

...and it should work this time

@Naren-hybreeder
Copy link

Thanks for the reply. I tried your steps and I got one error

Fatal error: Uncaught TypeError: Argument 1 passed to Mailgun\Mailgun::__construct() must be an instance of Mailgun\HttpClient\HttpClientConfigurator, string given, called in /home4/test/demo.test.com/mailgun/test.php on line 5 and defined in /home4/test/demo.test.com/mailgun/vendor/mailgun/mailgun-php/src/Mailgun.php:55 Stack trace: #0 /home4/test/demo.test.com/mailgun/test.php(5): Mailgun\Mailgun->__construct('68626feacf20c5e...') #1 {main} thrown in /home4/test/demo.test.com/mailgun/vendor/mailgun/mailgun-php/src/Mailgun.php on line 55

@DavidGarciaCat
Copy link
Author

How are you booting up the Mailgun Client? Please note that you are not supposed to use new Mailgun

Please check this: https://github.com/mailgun/mailgun-php#usage

@AlexanderGW
Copy link

Those additional dependencies resolve the PSR7 discovery issue for me, thanks @DavidGarciaCat

@DavidGarciaCat
Copy link
Author

👍 glad it helped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment