PHP code example of gajus / drill

1. Go to this page and download the library: Download gajus/drill library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gajus / drill example snippets


/**
 * @param string $key Mandrill API key.
 */
$drill = new \Gajus\Drill\Client('NlLdhX5FVKS55VBK1xPW_g');

/**
 * @see https://mandrillapp.com/api/docs/messages.JSON.html
 * @param string $path
 * @param array $parameters
 */
$response = $drill->api('messages/send', [
    'message' => [
        'text' => 'Test',
        'subject' => 'test',
        'from_email' => '[email protected]',
        'to' => [
            ['email' => '[email protected]']
        ],
    ]
]);

array(1) {
  [0]=>
  array(4) {
    ["email"]=>
    string(15) "[email protected]"
    ["status"]=>
    string(4) "sent"
    ["_id"]=>
    string(32) "f65f65c266f74e2884344ccfff3bb337"
    ["reject_reason"]=>
    NULL
  }
}

$drill = new \Gajus\Drill\Client('fxBTBjWKxJ05K9MjkFak1A');

try {
  $response = $drill->api('messages/send', [
      'message' => [
          'text' => 'Test',
          'subject' => 'test',
          'from_email' => 'invalidemail',
          'to' => [
              ['email' => '[email protected]']
          ],
      ]
  ]);
} catch (\Gajus\Drill\Exception\RuntimeException\ValidationErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\UserErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\UnknownSubaccountException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\PaymentRequiredException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\GeneralErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\ValidationErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException $e) {
    // All possible API errors.
} catch (\Gajus\Drill\Exception\InvalidArgumentException $e) {
    // Invalid SDK use errors.
} catch (\Gajus\Drill\Exception\DrillException $e) {
    // Everything.
}