Skip to main content

Prerequisites

Using SDK

This example is based on the Mailrify’s official mailrify-php SDK library.
1

Install SDK

composer require mailrify/mailrify-php
2

Initialize SDK

Get the API key from the Mailrify dashboard and initialize the SDK.
require __DIR__ . '/vendor/autoload.php';

use Mailrify\Sdk\Client;

$mailrify = Client::create([
  'apiKey'  => 'YOUR_API_KEY',
]);
3

Send email

$response = $mailrify->emails()->send([
    'from'    => 'Your app <[email protected]>',
    'to'      => '[email protected]',
    'subject' => 'Welcome to Mailrify 🚀',
    'html'    => '<p>It works! 👋</p>',
    'text'    => 'It works!',
    'headers' => [
        'X-Custom-Header' => 'Custom Value',
    ]
]);

echo $response->emailId;
Custom headers are forwarded as-is. Mailrify only manages the X-Usesend-Email-ID and References headers.

Adding contacts programatically

1

Get the contact book id

Get the contact book id from the Mailrify dashboard. Copy the contact book id.
2

Add contacts

 $mailrify->contacts()->create('contactId', [
      'email'     => '[email protected]',
      'firstName' => 'John',
      'lastName'  => 'Doe'
 ]);
3

Update contact

 $mailrify->contacts()->update('contactBookId', 'contactId', [
      'email'     => '[email protected]',
      'firstName' => 'John',
      'lastName'  => 'Doe'
 ]);