Sending email using mailgun PHP API
09:53 26 Jan 2015

I am trying to send an email with mailguns PHP api:

define('MAILGUN_KEY', 'key-ExamPle3xAMPle');
define('MAILGUN_DOMAIN', 'example.com');

$mailgun = new Mailgun\Mailgun(MAILGUN_KEY);

$mailgun->sendMessage(MAILGUN_DOMAIN, [
                'from'      => 'noreply@signstoptt.com',
                'to'        => $email,
                'subject'   => 'Sign Stop mailing list confirmation.',
                'html'      => "
                    Hello{$name},

This is a test." ]);

I have even tried to use array() instead of [ ].

I receive the following error in my php error log:

MissingRequiredParameters

It implies that what I am passing to the post function is incomplete or incorrect. upon inspecting the post function in the RestClient, I see that the function requires 2 arrays and not 1, so I tried adding a 2nd array with message attachments and it just got more errors, this time with guzzle (a dependency for mailgun)

[26-Jan-2015 14:32:50 UTC] PHP Fatal error:  Uncaught exception 'Mailgun\Connection\Exceptions\MissingRequiredParameters' with message 'The parameters passed to the API were invalid. Check your inputs!' in C:\Users\Zachary\Documents\NetBeansProjects\SS_MailingList\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php:187
    Stack trace:
    #0 C:\Users\Zachary\Documents\NetBeansProjects\SS_MailingList\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php(116): Mailgun\Connection\RestClient->responseHandler(Object(Guzzle\Http\Message\Response))
    #1 C:\Users\Zachary\Documents\NetBeansProjects\SS_MailingList\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(106): Mailgun\Connection\RestClient->post('signstoptt.com/...', Array, Array)
    #2 C:\Users\Zachary\Documents\NetBeansProjects\SS_MailingList\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(53): Mailgun\Mailgun->post('signstoptt.com/...', Array, Array)
    #3 C:\Users\Zachary\Documents\NetBeansProjects\SS_MailingList\subscribe.php(26): Mailgun\Mailgun->sendMessage('signstoptt.com', Array)
    #4 in C:\Users\Zachary\Documents\NetBeansProjects\SS_MailingList\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php on line 187

Has anyone else had this problem. I am running the site on a glassfish server setup by netbeans. I also used composer to install mailgun and its dependencies.

EDIT: Added more information.

init.php

OptInHandler();

subscribe.php

get('address/validate', [
            'address' => $email
        ])->http_response_body;

    if($validate->is_valid)
        {
            $hash = $mailgunOptIn->generateHash(MAILGUN_LIST, MAILGUN_SECRET, $email);

            $result = $mailgun->sendMessage(MAILGUN_DOMAIN, [
                'from'      => 'noreply@example.com',
                'to'        => $email,
                'subject'   => 'example mailing list confirmation.',
                'html'      => "
                    Hello{$name},

You submitted a request to join our mailing list, to confirm this subscription please click on the link provided below.

http://localhost:8000/confirm.php?hash={$hash}" ]); $mailgun->post('lists/' . MAILGUN_LIST . '/members', [ 'name' => $name, 'address' => $email, 'subscribed' => 'no' ]); header('Location: ./'); } } ?> Subscribe | Mailing list
php email guzzle mailgun