Giter Site home page Giter Site logo

mailgun-php's Introduction

Mailgun PHP client

This is the Mailgun PHP SDK. This SDK contains methods for easily interacting with the Mailgun API. Below are examples to get you started. For additional examples, please see our official documentation at http://documentation.mailgun.com

Latest Version Total Downloads Join the chat at https://gitter.im/mailgun/mailgun-php

Installation

To install the SDK, you will need to be using Composer in your project. If you aren't using Composer yet, it's really simple! Here's how to install composer:

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

Required minimum php version

  • minimum php version 7.4

The Mailgun API Client is not hard coupled to Guzzle, Buzz or any other library that sends HTTP messages. Instead, it uses the PSR-18 client abstraction. This will give you the flexibility to choose what PSR-7 implementation and HTTP client you want to use.

If you just want to get started quickly you should run the following command:

composer require mailgun/mailgun-php symfony/http-client nyholm/psr7

Usage

You should always use Composer autoloader in your application to automatically load your dependencies. All the examples below assume you've already included this in your file:

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

Here's how to send a message using the SDK:

// First, instantiate the SDK with your API credentials
$mg = Mailgun::create('key-example'); // For US servers
$mg = Mailgun::create('key-example', 'https://api.eu.mailgun.net'); // For EU servers

// Now, compose and send your message.
// $mg->messages()->send($domain, $params);
$mg->messages()->send('example.com', [
  'from'    => '[email protected]',
  'to'      => '[email protected]',
  'subject' => 'The PHP SDK is awesome!',
  'text'    => 'It is so simple to send a message.'
]);

Attention: $domain must match to the domain you have configured on app.mailgun.com.

Usage of new method for updating web scheme

# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = Mailgun::create('KEY', 'FULL_DOMAIN_URL');
$domain = "DOMAIN";

# Issue the call to the client.
$result = $mgClient->domains()->updateWebScheme($domain, 'https');

print_r($result);

Update web prefix

# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = Mailgun::create('KEY', 'FULL_DOMAIN_URL');
$domain = "DOMAIN";

# Issue the call to the client.
$result = $mgClient->domains()->updateWebPrefix($domain, 'tracking');
print_r($result);
  • Example of response
Mailgun\Model\Domain\WebPrefixResponse Object
(
    [message:Mailgun\Model\Domain\AbstractDomainResponse:private] => Domain web prefix updated
    [domain:Mailgun\Model\Domain\AbstractDomainResponse:private] =>
    [inboundDnsRecords:Mailgun\Model\Domain\AbstractDomainResponse:private] => Array
        (
        )
    [outboundDnsRecords:Mailgun\Model\Domain\AbstractDomainResponse:private] => Array
        (
        )
)

Custom http request to the API

<?php
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = Mailgun::create('KEY', 'ENDPOINT');
$domain = "DOMAIN";

$path = 'some path';
$params = [];

# Issue the call to the client.
$resultPost = $mgClient->httpClient()->httpPost($path, $params);

$resultGet = $mgClient->httpClient()->httpGet($path, $params);

$resultPut = $mgClient->httpClient()->httpPut($path, $params);

$resultDelete = $mgClient->httpClient()->httpDelete($path, $params);

SubAccounts

//Enable Sub Account
try {
    $items = $mgClient->subaccounts()->enable($id);
} catch (Exception $exception) {
    echo sprintf('HTTP CODE - %s,', $exception->getCode());
    echo sprintf('Error - %s', $exception->getMessage());
}

//Create a new Sub Account
try {
    $items = $mgClient->subaccounts()->create('some name');
} catch (Exception $exception) {
    echo sprintf('HTTP CODE - %s,', $exception->getCode());
    echo sprintf('Error - %s', $exception->getMessage());
}

//Get All
try {
    $items = $mgClient->subaccounts()->index();

    print_r($items->getItems());
} catch (Exception $exception) {
    echo sprintf('HTTP CODE - %s,', $exception->getCode());
    echo sprintf('Error - %s', $exception->getMessage());
}

Performing API Requests "On Behalf Of" Subaccounts

More Detailed you can read here - https://help.mailgun.com/hc/en-us/articles/16380043681435-Subaccounts#01H2VMHAW8CN4A7WXM6ZFNSH4R

$mgClient = Mailgun::create(
    'xxx',
    'yyy',
    $subAccountId
);
use Mailgun\HttpClient\HttpClientConfigurator;
use Mailgun\Hydrator\NoopHydrator;

$configurator = new HttpClientConfigurator();
$configurator->setEndpoint('http://bin.mailgun.net/aecf68de');
$configurator->setApiKey('key-example');
$configurator->setSubAccountId($subAccountId)

All usage examples

You will find more detailed documentation at /doc and on https://documentation.mailgun.com.

Response

The result of an API call is, by default, a domain object. This will make it easy to understand the response without reading the documentation. One can just read the doc blocks on the response classes. This provides an excellent IDE integration.

$mg = Mailgun::create('key-example');
$dns = $mg->domains()->show('example.com')->getInboundDNSRecords();

foreach ($dns as $record) {
  echo $record->getType();
}

If you'd rather work with an array than an object you can inject the ArrayHydrator to the Mailgun class.

use Mailgun\Hydrator\ArrayHydrator;

$configurator = new HttpClientConfigurator();
$configurator->setApiKey('key-example');

$mg = new Mailgun($configurator, new ArrayHydrator());
$data = $mg->domains()->show('example.com');

foreach ($data['receiving_dns_records'] as $record) {
  echo isset($record['record_type']) ? $record['record_type'] : null;
}

You can also use the NoopHydrator to get a PSR7 Response returned from the API calls.

Warning: When using NoopHydrator there will be no exceptions on a non-200 response.

Debugging

Debugging the PHP SDK can be helpful when things aren't working quite right. To debug the SDK, here are some suggestions:

Set the endpoint to Mailgun's Postbin. A Postbin is a web service that allows you to post data, which then you can display it through a browser. Using Postbin is an easy way to quickly determine what data you're transmitting to Mailgun's API.

Step 1 - Create a new Postbin. Go to http://bin.mailgun.net. The Postbin will generate a special URL. Save that URL.

Step 2 - Instantiate the Mailgun client using Postbin.

Tip: The bin id will be the URL part after bin.mailgun.net. It will be random generated letters and numbers. For example, the bin id in this URL (http://bin.mailgun.net/aecf68de) is aecf68de.

use Mailgun\HttpClient\HttpClientConfigurator;
use Mailgun\Hydrator\NoopHydrator;

$configurator = new HttpClientConfigurator();
$configurator->setEndpoint('http://bin.mailgun.net/aecf68de');
$configurator->setApiKey('key-example');
$configurator->setDebug(true);

$mg = new Mailgun($configurator, new NoopHydrator());

# Now, compose and send your message.
$mg->messages()->send('example.com', [
  'from'    => '[email protected]',
  'to'      => '[email protected]',
  'subject' => 'The PHP SDK is awesome!',
  'text'    => 'It is so simple to send a message.'
]);

Additional Info

For usage examples on each API endpoint, head over to our official documentation pages.

This SDK includes a Message Builder, Batch Message.

Message Builder allows you to quickly create the array of parameters, required to send a message, by calling a methods for each parameter. Batch Message is an extension of Message Builder, and allows you to easily send a batch message job within a few seconds. The complexity of batch messaging is eliminated!

Framework integration

If you are using a framework you might consider these composer packages to make the framework integration easier.

Contribute

This SDK is an Open Source under the MIT license. It is, thus, maintained by collaborators and contributors.

Feel free to contribute in any way. As an example you may:

  • Trying out the dev-master code
  • Create issues if you find problems
  • Reply to other people's issues
  • Review PRs

Running the test code

If you want to run the tests you should run the following commands:

git clone [email protected]:mailgun/mailgun-php.git
cd mailgun-php
composer update
composer test

Support and Feedback

Be sure to visit the Mailgun official documentation website for additional information about our API.

If you find a bug, please submit the issue in Github directly. Mailgun-PHP Issues

As always, if you need additional assistance, drop us a note through your account at https://app.mailgun.com/support.

mailgun-php's People

Contributors

aradoje avatar cerealean avatar davidgarciacat avatar finwe avatar indapublic avatar iwahara avatar jchamberlain avatar littlesqx avatar martin-sanjuan avatar maximzasorin avatar mikeundefined avatar nathanntg avatar nmenglund avatar nyholm avatar obukhov-sergey avatar oleksandr-mykhailenko avatar pavlico avatar pirogoeth avatar qpautrat avatar semijoelon avatar shakaran avatar svenbw avatar sykezz avatar temirkhann avatar tomschlick avatar travelton avatar yoye avatar z38 avatar zacbrownpayleven avatar zebulanstanphill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailgun-php's Issues

Put Request on Routes

Suspected: Actions seem to be unordered after issuing a PUT request on a Route. Needs more research.

inline image php error

Getting the following warning when trying to add an inline image to a message via mailgun php. Email is sent, but there is no inline image

Warning: Invalid argument supplied for foreach() in /var/www/html/blahblahblah.com/public/php/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php on line 65

using mailgun 1.7 and using the following sample code as a guide:

Include the Autoloader (see "Libraries" for install instructions)

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

Instantiate the client.

$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$domain = "samples.mailgun.org";

Make the call to the client.

$result = $mgClient->sendMessage("$domain",
array('from' => 'Excited User [email protected]',
'to' => '[email protected]',
'cc' => '[email protected]',
'bcc' => '[email protected]',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!',
'html' => 'Inline image: '),
array('inline' => '@/path/to/test.jpg'));

Get list members limit

Using a simple wrapper in Laravel 4, I am trying to get the members of a particular list that has 2000+ members.

Mailgun::get("lists/$address/members", array(
'subscribed' => 'yes',
'limit' => 50,
'skip' => 0)
);
Of course the default (as indicated in the docs) is 100.
As soon as I set the limit over 100, I get this error:
The parameters passed to the API were invalid. Check your inputs!

How To Parse Incoming Email Using API?

Hello. I have set up a route that POSTs to a URL on my server. I would like sample code showing how to parse the incoming message fields from the request using php.

Only the following code is provided in the documentation. (this is Django code).

# Handler for HTTP POST to http://myhost.com/messages for the route defined above
def on_incoming_message(request):
     if request.method == 'POST':
         sender    = request.POST.get('sender')
         recipient = request.POST.get('recipient')
         subject   = request.POST.get('subject', '')

         body_plain = request.POST.get('body-plain', '')
         body_without_quotes = request.POST.get('stripped-text', '')
         # note: other MIME headers are also posted here...

         # attachments:
         for key in request.FILES:
             file = request.FILES[key]
             # do something with the file

     # Returned text is ignored but HTTP status code matters:
     # Mailgun wants to see 2xx, otherwise it will make another attempt in 5 minutes
     return HttpResponse('OK')

http://documentation.mailgun.com/quickstart.html#receiving-and-parsing-email

Would you please provide a sample that does the exact same thing in php?

Thank you.

Any interest in merging concerns?

Hey, I couldn't find a good way to get in touch via the documentation site, so I thought I'd just send a quick note through here.

I created a php mailgun api wrapper a couple months before you guys released this one. Would you have any interest in collaborating to find a way to merge my code base (or maybe certain aspects of the code base) into this library?

I don't see any point in having "competing" libraries that are working towards the same goal, but I also feel that there might be some value in my code that could enhance this library?

You can check out my code base here, https://github.com/chriswoodford/mailgun-php
Let me know your thoughts

thanks,
Chris

Missing endpoint

PHP Fatal error: Uncaught exception 'Mailgun\Connection\Exceptions\MissingEndpoint' with message 'The endpoint you've tried to access does not exist. Check your URL.' in vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:132

When checking the $responseObj it yields the following endpoint:

[reasonPhrase:protected] => Not Found
[statusCode:protected] => 404
[info:protected] => Array
    (
        [url] => HTTP://https.se/messages
        [content_type] => text/html

My domain name is https.se

Control testmode settings for entire instances, with delivery override option

I would find it useful to be able to put an entire Mailgun instance into testmode. All I can find in the current version is the ability to add the testmode flag to messages. I'm seeing three useful settings to store and use:

  1. Testmode (true/false). If true, mailgun-php would behave as directed by the next two settings.
  2. Send in testmode (true/false). If true, mailgun-php would ensure that the o:testmode flag existed on each message sent. If false, mailgun-php would skip the actual API call.
  3. Testmode delivery override (any valid "To" field content). If set, mailgun-php would strip out To, Cc, and Bcc content and insert the override value into the To field. Additionally, it might append the stripped content onto the end of the email as a note, or as an attachment.

Thoughts? Am I missing another way of accomplishing this sort of thing?

Requirement for Guzzle is restrictive

Currently this library requires a fixed version of Guzzle:

"guzzle/guzzle": "3.7.1"

This causes problems when trying to install other libraries that have a more relaxed set of requirements, eg aws-sdk-php:

"guzzle/guzzle": "~3.7.0"

I suggest the mailgun-php also uses tilde or wildcard matching as ~3.7.0 or 3.7.* should provide a consistent API.

Mark...

Unable to attach file from php

Test code is here

$file_name = "/public_html/solfreaks/test/uploads/4-29-2015 2-21-46 PM.png";
$messageBldr->addAttachment($file_name);
//$messageBldr->setDeliveryTime("tomorrow 8:00AM", "PST");
$messageBldr->setClickTracking(true);
print_r($messageBldr);

        # Finally, send the message.
        $return = $mg->post("{$domain}/messages", $messageBldr->getMessage(), $messageBldr->getFiles());    

POst array

Mailgun\Messages\MessageBuilder Object
(
[message:protected] => Array
(
[from] => Array
(
[0] => 'hareem haque'
)

        [to] => Array
            (
                [0] => 'Ahmed ANees' 
            )

        [subject] => A message from the PHP SDK using Message Builder!
        [text] => This is the text body of the message!
        [o:tracking-clicks] => yes
    )

[variables:protected] => Array
    (
    )

[files:protected] => Array
    (
        [attachment] => Array
            (
                [0] => Array
                    (
                        [filePath] => /public_html/solfreaks/test/uploads/4-29-2015 2-21-46 PM.png
                        [remoteName] => 
                    )

            )

    )

[counters:protected] => Array
    (
        [recipients] => Array
            (
                [to] => 1
                [cc] => 0
                [bcc] => 0
            )

        [attributes] => Array
            (
                [attachment] => 0
                [campaign_id] => 0
                [custom_option] => 0
                [tag] => 0
            )

    )

)

Can't install Mailgun library

Dear Support team,

I have been trying to install mailgun library in my localhost using composer. I wrote in the command prompt the following commands:

  • php composer require mailgun/mailgun-php:~1.3
    it gives me error as:

c:\mailgun-php>php composer.phar require mailgun/mailgun-php:~1.3
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package mailgun/mailgun-php 1.0.0 could not be found.
Problem 2
- guzzle/guzzle v3.7.4 requires ext-curl * -> the requested PHP extension cu
rl is missing from your system.
- guzzle/guzzle v3.7.3 requires ext-curl * -> the requested PHP extension cu
rl is missing from your system.
- guzzle/guzzle v3.7.2 requires ext-curl * -> the requested PHP extension cu
rl is missing from your system.
- guzzle/guzzle v3.7.1 requires ext-curl * -> the requested PHP extension cu
rl is missing from your system.
- guzzle/guzzle v3.7.0 requires ext-curl * -> the requested PHP extension cu
rl is missing from your system.
- Installation request for guzzle/guzzle 3.7.* -> satisfiable by guzzle/guzz
le[v3.7.0, v3.7.1, v3.7.2, v3.7.3, v3.7.4].

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common
problems.

Installation failed, reverting ./composer.json to its original content.

Please help me how to resolve it.

CC/BCC is ignored when using MIME message

I'am creating email message with SwiftMailer, than casting it toString() and passing it as 3rd parameter to sendMessage() function, as shown in documentation: https://documentation.mailgun.com/user_manual.html#sending-via-api
section: "Sending a MIME message which you pre-build yourself using a MIME library of your choice"

$result = $mgClient->sendMessage(
    $domain, array(
        'to' => '[email protected]'
    ),
    $message->toString()
);

however cc and bcc message headers are ignored and email is sent only to to recipient.

example of my MIME message:

Message-ID: <[email protected]>
Date: Tue, 28 Apr 2015 14:05:30 +0200
Subject: test
From: [email protected]
To: [email protected]
Cc: [email protected]
Bcc: [email protected]
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Mailgun-Drop-Message: yes

testing cc/bcc

Way to set attachment name?

Currently you add an attachment by file path. Is there a way to set a custom name for the attachment that is distinct from the path?

Fatal error: Uncaught exception thrown during sendMessage()

Hi getting following error while using sendMessage(), before it was working fine.

Fatal error: Uncaught exception 'Mailgun\Connection\Exceptions\MissingRequiredParameters' with message 'The parameters passed to the API were invalid. Check your inputs!' in C:\xampp\htdocs\Mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php:125 Stack trace: #0 C:\xampp\htdocs\Mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php(90): Mailgun\Connection\RestClient->responseHandler(Object(Guzzle\Http\Message\Response)) #1 C:\xampp\htdocs\Mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(56): Mailgun\Connection\RestClient->post('samples.mailgun...', Array, Array) #2 C:\xampp\htdocs\Mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(37): Mailgun\Mailgun->post('samples.mailgun...', Array, Array) #3 C:\xampp\htdocs\Mailgun\index.php(17): Mailgun\Mailgun->sendMessage('samples.mailgun...', Array) #4 {main} thrown in C:\xampp\htdocs\Mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php on line 125

require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$domain = "samples.mailgun.org";

$result = $mgClient->sendMessage($domain, array(
'from' => '[email protected]',
'to' => 'Baz [email protected]',
'subject' => 'Testing Mailgun',
'text' => 'Testing some Mailgun awesomness!'
));

Batch Message Unique ID

The batch message handler is failing to add unique IDs for each recipient, when not defined. While it's not required, it's a nice to have.

DEFAULT_TIME_ZONE is not define

DEFAULT_TIME_ZONE constant is not defined and it's used when MessageBuilder::setDeliveryTime() method is called without TimeZone argument.

Could you please add the constant ? I can do a pull request but as an European I'm not sure I'll to define the correct one.

MissingEndpoint exception thrown during sendMessage()

Haven't done much investigation yet, thought I should report it anyway.

PHP Fatal error: Uncaught exception 'Mailgun\Connection\Exceptions\MissingEndpoint' with message 'The endpoint you've tried to access does not exist. This might be a bug! Notify [email protected].' in vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:95
Stack trace:
#0 vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(52): Mailgun\Connection\RestClient->responseHandler(Object(Guzzle\Http\Message\Response))
#1 vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(60): Mailgun\Connection\RestClient->post('...', Array, Array)
#2 vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(38): Mailgun\Mailgun->post('...', Array, Array)

...

Can you please guide me how can i get all emails from mailgun in my local

Can you please guide me how can i get all emails from mailgun in my local,
I need to show all emails in my local db . For this i am trying to fetch all emails .

Please help me

I am trying below code it does not do any thing
use Mailgun\Mailgun;
$mg = new Mailgun("XXXXXXX");
$domain = "my.domain";

$result = $mg->get("$domain/messages");

Error:

Fatal error: Uncaught exception 'Mailgun\Connection\Exceptions\GenericHTTPError' with message 'An HTTP Error has occurred! Check your network connection and try again.' in D:\wamp\www\test\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php on line 136

PHP 5.5 Timezone Offset, Potential PHP Bug?

Update Mailgun to use GuzzleHttp

Please update the http request methods to use the latest GuzzleHttp package. This is useful because it helps prevent redundancy in up-to-date packages from having to download both GuzzleHttp\ and Guzzle\ packages.

The endpoint you've tried to access does not exist

I am getting this error when trying to send a simple email. I have double checked my domain as that was the solution for the few other people who had the same issue, I'm sure its the same one I used to set up my malign account.

  <br />
  <b>Notice</b>:  Array to string conversion in <b>/var/www/html/php_libs/vendor/mailgun/mailgun-     php/src/Mailgun/Mailgun.php</b> on line <b>36</b><br />
 <br />
 <b>Fatal error</b>:  Uncaught exception 'Mailgun\Connection\Exceptions\MissingEndpoint' with message 'The endpoint you've tried to access does not exist. Check your URL.' in /var/www/html/php_libs/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:133
 Stack trace:
 #0 /var/www/html/php_libs/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(90): Mailgun\Connection\RestClient-&gt;responseHandler(Object(Guzzle\Http\Message\Response))
 #1 /var/www/html/php_libs/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(80): Mailgun\Connection\RestClient-&gt;post('Array/messages', Array, Array)
 #2 /var/www/html/php_libs/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(36): Mailgun\Mailgun-&gt;post('Array/messages', Array, Array)
 #3 /var/www/html/api/newuser.php(136): Mailgun\Mailgun-&gt;sendMessage(Array, Array)
 #4 {main}
 thrown in <b>/var/www/html/php_libs/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php</b> on line <b>133</b><br />

my code:

 require '/var/www/html/php_libs/vendor/autoload.php';
 use Mailgun\Mailgun;
 $mg = new Mailgun("key-3f2814XXXXXXX");
 $domain = 'stnatoday.com';
 $mg->sendMessage($domain, array('from'    => '[email protected]', 
                            'to'      => trim($_REQUEST['identifier']), 
                            'subject' => 'The PHP SDK is awesome!', 
                            'text'    => 'It is so simple to send a message.'));

Proper message if the queue is full.

If the mail queue for the domain is full the SDK returns an unclear message:

The parameters passed to the API were invalid. Check your inputs!

Mailgun API Compatability with Godaddy/PHP 5.4

I developed a little php script that makes use of the curl API, and allows for multiple attachments, naming of attachments and sending of html/plain text email... it is super basic, however it is useful for anyone who is on Godaddy as it seems they have a block on outgoing SMTP and also their servers seem to operate on PHP 5.4 which doesn't seem to support namespacing as far as I can tell. Here is a link to the project in case you guys are interested in the idea, just thought I would let you guys know! :)

https://github.com/NerdsvilleCEO/NerdsvilleMailgunAPI/blob/master/NerdsvilleMailGun.php

Limit in get bounces

If limit is over 1000 i got error http://thecode.punbb.org.ua/get/raw:9S6F3qsTIkwlYn/lq4oivjll3.php

code
$mgClient = new Mailgun($config->mailgun->key);
$domain = $config->mailgun->domain;
$result = $mgClient->get("$domain/bounces", array('skip' => 0, 'limit' => 2000));

PHP 5.3.23 (cli) (built: Mar 18 2013 21:54:26)
"mailgun/mailgun-php": "v1.7.1"

If i made request use desktop rest-client - all working fine.

addAttachment() throws missing arguments error

Testing the Message Builder example code with a simple addAttachment("@/var/www/smiledance.gif");

The image exists and is readable.

The script works fine and sends the email if I comment out the addAttachment line.

Tested on two LAMP servers, the latest on a fresh Ubuntu 13.10 with PHP Version 5.5.3-1ubuntu2.1.

The script throws:
Uncaught exception 'Mailgun\Connection\Exceptions\MissingRequiredParameters' with message 'The parameters passed to the API were invalid. Check your inputs!' in /var/www/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:105 Stack trace: #0 /var/www/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(70): Mailgun\Connection\RestClient->responseHandler(Object(Guzzle\Http\Message\Response)) #1 /var/www/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(60): Mailgun\Connection\RestClient->post('example.com/messag...', Array, Array) #2 /var/www/rifle.php(27): Mailgun\Mailgun->post('example.com/messag...', Array, Array) #3 {main} thrown in /var/www/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php on line 105

Can someone confirm?

Fatal error: Class 'Mailgun\Connection\RestClient' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Mailgun.php on line 38

I'm getting an error while trying to use this PHP SDK (not installed through Composer, I really prefer managing code dependencies manually so as to minimise them).

To fix the above error I can add the line require "Connection/RestClient.php"; just above the first class declaration in Mailgun.php, but this in turn causes the error

Fatal error: Class 'GuzzleHttp\Client' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Connection/RestClient.php on line 41

and I imagine if I kept going I'd be caught in a big tangled web of them.

I'm really hoping that this is just a matter of a required PHP module being missing, but my question on StackOverflow did not get any answers, so I'm posting here.

RestClient::responseHandler fails at downloading stored message attachments

On line 81 on Mailgun\Connection\RestClient the response is always assumed to be a JSON string. This is not the case when downloading attachments for stored messages. The data that comes back is raw file data. JSON decoding fails the http_response_body parameter is set to null.

I cannot download attachments directly either as the API end point requires authentication.

Currently, the only solution is issue a separate request and manually set authentication details to download the attachment.

It would be nice if this could be fixed to properly handle non JSON responses so we didn't have to issue API calls from outside the library.

Message Builder Reply To Bug

Function setReplyToAddress() should be a single value field. The Mailgun API does not accept an array for parameter "h:reply-to". The function "addRecipient()" will need another if statement to check for headerName = "h:reply-to" and assign the value instead of nesting an array.

The parameters passed to the API were invalid error when passing an array for groupby

Hi,

I used to be able to group clicks by both link and recipient to enable "spy mode" which is used in the advanced examples.

$result = $mailgun->get("$domain/campaigns/$campaign_id/clicks", ['groupby' => ['link', 'recipient']]);

But this is now causing an MissingRequiredParameters exception to be thrown, if I change this to just a string e.g.

$result = $mailgun->get("$domain/campaigns/$campaign_id/clicks", ['groupby' => 'link']);

I get the expected result, how can I still pass 2 groupby parameters?

won't get mails from php sdk in mailgun

trying to get the json data of mailgun
$queryString = array(
'begin' => 'Fri, 3 May 2013 09:00:00 -0000',
'ascending' => 'yes',
'limit' => 25,
'pretty' => 'yes',
'subject' => 'test'
);

Make the call to the client.

$result = $mgClient->get("$domain/events", $queryString);
is there is any http header to set in this?

Renaming attachments not working

I haven't been able to send attachments using the new method to rename the attachments.

Here is the test code I used:

# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('my-key');
$domain = "my-domain";

# Make the call to the client.

try {
    //Version 1 | from docs (old)
    $result = $mgClient->sendMessage("$domain",
        array(
            'from'    => 'Excited User <[email protected]>',
            'to'      => '[email protected]',
            'subject' => 'Version 1 | from docs (old)',
            'text'    => 'Testing some Mailgun awesomness!',
            'html'    => '<html>HTML version of the body</html>'
        ),
        array(
            'attachment' => array(
                '@C:\Projects\Sandbox\mailgun\testfile_1.txt',
                '@C:\Projects\Sandbox\mailgun\testfile_2.txt'
            )
        )
    );
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    // Version 2 | New version with attachment renaming (without 'attachment' key)
    $result = $mgClient->sendMessage("$domain",
        array(
            'from'    => 'Excited User <[email protected]>',
            'to'      => '[email protected]',
            'subject' => "Version 2 | New version with attachment renaming (without 'attachmnt' key)",
            'text'    => 'Testing some Mailgun awesomness!',
            'html'    => '<html>HTML version of the body</html>'
        ),
        array(
            array(
                'filePath' => '@C:\Projects\Sandbox\mailgun\testfile_1.txt',
                'remoteName' => 'NumberOne.txt'
            ),
            array(
                'filePath'   => '@C:\Projects\Sandbox\mailgun\testfile_2.txt', 
                'remoteName' => 'NumberTwo.txt'
            )
        )
    );
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    //Version 3 | New version with attachment renaming (with 'attachment' key) 
    $result = $mgClient->sendMessage("$domain",
        array(
            'from'    => 'Excited User <[email protected]>',
            'to'      => '[email protected]',
            'subject' => "Version 3 | New version with attachment renaming (with 'attachment' key)",
            'text'    => 'Testing some Mailgun awesomness!',
            'html'    => '<html>HTML version of the body</html>'
        ),
        array(
            'attachment' => array(
                'filePath' => '@C:\Projects\Sandbox\mailgun\testfile_1.txt',
                'remoteName' => 'NumberOne.txt'
            ),
            'attachment' => array(
                'filePath'   => '@C:\Projects\Sandbox\mailgun\testfile_2.txt', 
                'remoteName' => 'NumberTwo.txt'
            )
        )
    );
} catch (Exception $e) {
    var_dump($e->getMessage());
}

After running the above I only receive the first two emails.
Here are the results per version/mail:

  • Version 1: No problems, email arrives with the two attachments
  • Version 2: Email arrives without attachments
  • Version 3: Throws exception "Unable to open NumberTwo.txt for reading" (see below)
Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open NumberTwo.txt for reading' in C:\Projects\Sandbox\mailgun\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php:53 
Stack trace: 
#0 C:\Projects\Sandbox\mailgun\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php(28): Guzzle\Http\Message\PostFile->setFilename('NumberTwo.txt') 
#1 C:\Projects\Sandbox\mailgun\vendor\guzzle\guzzle\src\Guzzle\Http\Message\EntityEnclosingRequest.php(199): Guzzle\Http\Message\PostFile->__construct('attachment', 'NumberTwo.txt', NULL, NULL) 
#2 C:\Projects\Sandbox\mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php(55): Guzzle\Http\Message\EntityEnclosingRequest->addPostFile('attachment', 'NumberTwo.txt') 
#3 C:\Projects\Sandbox\mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(60): Mailgun\Connection\RestClient->post('******/...', Array, Array) 
#4 C:\Projects\Sandbox\mailgun\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(38): Mailgun\Mail in C:\Projects\Sandbox\mailgun\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php on line 53

PHP code problem

namespace Mailgun\Connection;

use Guzzle\Http\Client as Guzzle;
use Mailgun\MailgunClient;

use Mailgun\Connection\Exceptions\GenericHTTPError;
use Guzzle\Http\QueryAggregator\DuplicateAggregator;
use Guzzle\Http\QueryAggregator\PhpAggregator;
use Mailgun\Connection\Exceptions\InvalidCredentials;
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
use Mailgun\Connection\Exceptions\MissingEndpoint;

I don't think this is the standard php.

Error:
Parse error: syntax error, unexpected T_STRING in
_D:www\me\perclick\my_addons\mailgun\Mailgun.php on line

3

Setting tags with BatchMessage()

When sending a message using sendMessage() you are able to set tags for the message using the wrapper.
You can also set a tag when using BatchMessage() using addCustomHeader().
This sets the same tag for all messages in the call. We would like to set individual tags also when using BatchMessage().
Do you think this can be achieved?
Thank you for a superb wrapper btw.

Can't add users to mailgun mailing lists

I try like the following that I was saw at the doc.

<?php
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$listAddress = '[email protected]';

# Issue the call to the client.
$result = $mgClient->post("lists/$listAddress/members", array(
    'address'     => '[email protected]',
    'name'        => 'Bob Bar',
    'description' => 'Developer',
    'subscribed'  => true,
    'vars'        => '{"age": 26}'
));

But I got the following errors

127.0.0.1:46067 [500]: /addmailinglist.php - Uncaught exception 'Mailgun\Connection\Exceptions\MissingRequiredParameters' with message 'The parameters passed to the API were invalid. Check your inputs!' in /mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:125
Stack trace:
#0 mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(90): Mailgun\Connection\RestClient->responseHandler(Object(Guzzle\Http\Message\Response))
#1 /mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(56): Mailgun\Connection\RestClient->post('lists/dev@sampl...', Array, Array)
#2 /mailgun/addmailinglist.php(17): Mailgun\Mailgun->post('lists/dev@sampl...', Array)
#3 {main}
  thrown in /mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php on line 125

When I tracke the errors, I know I miss two parameter. So add and test with empty paramater but I still got and errors.

Negative Events Filters Return Cause Empty Results

Passing a negative event filter string to the events API, such as "accepted -stored", always returns an empty result set, regardless of what events are actually logged.

I tried fixing this in #58, but my solution didn't work. This may be a bug in Guzzle 3.9.2.

try response function

Hi guys,

The script always fails if a ResponseCode is != 200. Would be great to implement a public function for simply check a endpointUrl. This would make life easier in process of cleanup bounceback and mailinglist recipients.

Thanks

Class 'Mailgun' not found

Hi,

Why I am getting the error Class 'Mailgun' not found. Screen shot is http://prntscr.com/4neel2 and code is as blow:

require 'vendor/autoload.php';

First, instantiate the SDK with your API credentials and define your domain.

$mg = new Mailgun("key-619-tq-f2v8oyb3zvn1rvojyp52lcef7");
$domain = "rs89818.mailgun.org";

Now, compose and send your message.

$mg->sendMessage($domain, array('from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Sent from mailgun title',
'text' => 'Sent from mailgun message.'));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.