Jay
Jay

Reputation: 53

mailgun send mail api PHP not working in GAE. Uncaught Error: Class 'Mailgun\Mailgun' not found

I have an issue sending mail with mailgun API in GAE flexible environment. I am thinking the error borders on the composer not able to load the 'vendor/autoload.php' files.

If possible to get the mailgun-php files in one piece, I can deploy and ignore using composer.json. Please I need help with this problem. I keep getting this error. I keep getting this error notwithstanding I have my composer.json file.

PHP message:

PHP Fatal error: Uncaught Error: Class 'Mailgun\Mailgun' not found in /app/sendmailgun.php"

mailgun.php

<?php 
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('xxxxxxx','https://api.mailgun.net'); //ERROR THROWN HERE. CANT FIND CLASS
$domain = "mail.xxxx.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from'  => 'ME<[email protected]>',
'to'    => 'YOU <[email protected]>',
'subject' => 'TEXT MAILGUN',
'html'    => '<html>SIMPLER AND EASIER</html>'

));
if ($result){

echo ("Email Sent");
}

composer.json

{
"name": "mailgun/mailgun-php",
"description": "The Mailgun SDK provides methods for all API functions.",
"require": {
    "php": "^7.1",
    "psr/http-client": "^1.0",
    "php-http/multipart-stream-builder": "^1.0",
    "php-http/client-common": "^1.9 || ^2.0",
    "php-http/discovery": "^1.6",
    "webmozart/assert": "^1.2"
},
"require-dev": {
    "phpunit/phpunit": "^7.5",
    "php-http/guzzle6-adapter": "^1.0",
    "nyholm/psr7": "^1.0",
    "nyholm/nsa": "^1.1"
},
"autoload": {
    "psr-4": {
        "Mailgun\\": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Mailgun\\Tests\\": "tests/"
    }
},
"suggest": {
    "php-http/curl-client": "cURL client for PHP-HTTP",
    "guzzlehttp/psr7": "PSR-7 message implementation that also provides common utility methods"
},
"license": "MIT",
"authors": [
    {
        "name": "Travis Swientek",
        "email": "[email protected]"
    }
],
"scripts": {
    "test": "vendor/bin/phpunit",
    "test-coverage": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
},
"extra": {
    "branch-alias": {
        "dev-master": "3.0-dev"
    }
}
}

Upvotes: 1

Views: 1419

Answers (1)

Jay
Jay

Reputation: 53

finally fixed the composer.json file. tnx Pierre for the clue.

composer.json

{
"require": {
    "Mailgun/Mailgun-php": "^1.0",
    "php-http/curl-client": "^1.0",
    "guzzlehttp/psr7": "^1.0",
    "php-http/message": "^1.0"
}

}

Upvotes: 1

Related Questions