1. Go to this page and download the library: Download mailbreeze/mailbreeze-php 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/ */
mailbreeze / mailbreeze-php example snippets
use MailBreeze\MailBreeze;
$client = new MailBreeze('your_api_key');
// Send an email
$email = $client->emails->send([
'from' => '[email protected]',
'to' => ['[email protected]'],
'subject' => 'Hello from MailBreeze!',
'html' => '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
]);
echo "Email sent with ID: " . $email['id'];
// Create list
$list = $client->lists->create([
'name' => 'Newsletter Subscribers',
'description' => 'Weekly newsletter recipients',
]);
// Add contact to list
$client->lists->addContact('list_123', 'contact_456');
// Remove contact from list
$client->lists->removeContact('list_123', 'contact_456');
// Get list contacts
$result = $client->lists->contacts('list_123');
// Get list statistics
$stats = $client->lists->stats('list_123');
// Verify single email
$result = $client->verification->verify(['email' => '[email protected]']);
if ($result['is_valid']) {
echo "Email is valid!";
} else {
echo "Email is invalid: " . $result['status'];
}
// Batch verification
$batch = $client->verification->batch([
'[email protected]',
'[email protected]',
'[email protected]',
]);
// Check batch status
$result = $client->verification->get($batch['verification_id']);
// List verification jobs
$verifications = $client->verification->list([
'page' => 1,
'limit' => 20,
]);
// Get verification statistics
$stats = $client->verification->stats();
// Create upload URL
$upload = $client->attachments->createUploadUrl([
'filename' => 'invoice.pdf',
'contentType' => 'application/pdf',
'size' => 102400,
]);
// Upload file to the URL
// Use your preferred HTTP client to PUT the file to $upload['uploadUrl']
// Use the attachment ID when sending emails
$email = $client->emails->send([
'from' => '[email protected]',
'to' => ['[email protected]'],
'subject' => 'Your Invoice',
'html' => '<p>Please find your invoice attached.</p>',
'attachmentIds' => [$upload['attachmentId']],
]);
$client = new MailBreeze('your_api_key', [
'base_url' => 'https://api.mailbreeze.com', // Custom API URL (default)
'timeout' => 30, // Request timeout in seconds
'max_retries' => 3, // Maximum retry attempts
'retry_delay' => 1000, // Base retry delay in milliseconds
]);