0

I installed Composer and a SDK for Mailgun's service. These are the steps i followed:

# current directory
cd ~

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

# Add Mailgun as a dependency
php composer.phar require mailgun/mailgun-php:~1.7

According to the instructions, all I did after that was (index.php):

<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# First, instantiate the SDK with your API credentials and define your domain.
$mg = new Mailgun("key-my-key-goes-here-987654321");
$domain = "somedomain.com";

Then, I tried to get the list of bounced emails:

$data = $mg->get("$domain/bounces", array('limit' => 15, 'skip'  => 0));
var_dump($data);

...and I'm getting this error:

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 2 Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/index.php on line 2

So I'm guessing it has something to do with composer's installation/configuration perhaps? Thanks for any help...

Andres SK
  • 10,779
  • 25
  • 90
  • 152

1 Answers1

1

The way you programmed it, you must have the following files all in the same directory:

composer.json
index.php (your test script)

And you must have run the composer require command while being inside this directory. This will also create a directory named vendor here, and add plenty of files, amongst them vendor/autoload.php.

If however your test script isn't in this location, the require call will not find the file where you tell PHP to find it. This isn't any failure of Composer, but simply the fact that you have to include that file according to your situation, not by copy&paste code. If you change the path of your test script, you have to change the path of the vendor directory as well.

Sven
  • 69,403
  • 10
  • 107
  • 109
  • Thanks for the tip, first time using Composer. I'll follow your steps in a few secs. Just one quick question though, the composer.json file is autogenerated when i run the composer require cmd? – Andres SK Apr 26 '14 at 20:56