PHP code example of emailit / emailit-sdk

1. Go to this page and download the library: Download emailit/emailit-sdk 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/ */

    

emailit / emailit-sdk example snippets




use EmailIt\EmailItClient;

$client = new EmailItClient('your_api_key');



use EmailIt\EmailItClient;

$client = new EmailItClient('your_api_key');

use EmailIt\EmailItClient;

$client = new EmailItClient('your_api_key');

$email = $client->email();
$email->from('[email protected]')
      ->to('[email protected]')
      ->replyTo('[email protected]')
      ->subject('Test Email')
      ->html('<h1>Hello, World!</h1>')
      ->text('This is a test email.')
      ->send();

$email = $client->email();
$email->from('[email protected]')
      ->to('[email protected]')
      ->replyTo('[email protected]')
      ->subject('Test Email')
      ->html('<h1>Hello, World!</h1>')
      ->text('This is a test email.')
      ->addAttachment('file.pdf', $fileContent, 'application/pdf')
      ->addHeader('X-Custom-Header', 'Value')
      ->send();

$audiences = $client->audiences();

// List audiences
$list = $audiences->list(25, 1, 'Newsletter');

// Create audience
$newAudience = $audiences->create('New Newsletter');

// Subscribe a user
$audiences->subscribe(
    'audience_token',
    '[email protected]',
    'John',
    'Doe',
    ['interests' => 'technology']
);

$credentials = $client->credentials();

// List credentials
$list = $credentials->list(25, 1, null, 'smtp');

// Create credential
$newCredential = $credentials->create('Main SMTP', 'smtp');

$domains = $client->sendingDomains();

// List domains
$list = $domains->list(25, 1, 'example.com');

// Create domain
$newDomain = $domains->create('emails.example.com');

// Check DNS records
$dnsStatus = $domains->checkDns('domain_id');

$events = $client->events();

// List events
$list = $events->list(25, 1, 'email.delivery.sent');

// Get specific event
$event = $events->get('event_id');

use EmailIt\EmailItException;

try {
    $result = $client->email()
        ->from('[email protected]')
        ->to('[email protected]')
        ->subject('Test')
        ->html('<p>Content</p>')
        ->send();
} catch (EmailItException $e) {
    echo 'Error: ' . $e->getMessage();
    echo 'Code: ' . $e->getCode();
}