I’m working with Mailgun PHP SDK version 3.5.2 which uses symfony/http-client by default. I want to switch to using guzzlehttp/guzzle instead but I’m running into issues.
Here’s what I tried:
public function sendEmail() {
// Initialize Guzzle client
$httpClient = new \GuzzleHttp\Client();
// Try to create Mailgun instance with Guzzle
$mailgun = Mailgun::create('key-example123', $httpClient);
// Send the email
$mailgun->messages()->send('mydomain.com', [
'from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Test message',
'text' => 'This is a test email message.'
]);
}
But I get this error:
Fatal error: Uncaught TypeError: Argument 2 passed to Mailgun\Mailgun::create() must be of the type string, object given
I also modified my composer.json to include guzzle:
{
"require": {
"php": "^7.3 || ^8.0",
"php-http/client-common": "^2.2.1",
"php-http/discovery": "^1.9.1",
"guzzlehttp/guzzle": "^7.0"
},
"suggest": {
"php-http/guzzle7-adapter": "HTTP client adapter"
}
}
What’s the proper way to configure Guzzle as the HTTP client for this Mailgun version? How can I resolve this type error?