PHP code example of zemailme / zemail-laravel

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

    

zemailme / zemail-laravel example snippets


use Zemail\Laravel\Zemail;

// Get account profile
$account = Zemail::account()->get();
echo "Account ID: {$account->id}, Email: {$account->email}, Tier: {$account->tier}\n";

// Get active subscription
$subscription = Zemail::account()->subscription();
echo "Status: {$subscription->status}, Tier: {$subscription->tier}\n";

// Get current resource & API usage
$usage = Zemail::account()->usage();
print_r($usage->mailboxes);
print_r($usage->storage);
print_r($usage->developerApi);

$domains = Zemail::domains()->list();

foreach ($domains->data as $domain) {
    echo "Domain: {$domain->name} (Types: " . implode(', ', $domain->allowedTypes) . ")\n";
}

$mailboxes = Zemail::mailboxes()->list(page: 1, limit: 10);

foreach ($mailboxes->data as $mailbox) {
    echo "Mailbox: {$mailbox->address} (ID: {$mailbox->id})\n";
}

if ($mailboxes->hasMore) {
    echo "Next cursor: {$mailboxes->nextCursor}\n";
}

$mailbox = Zemail::mailboxes()->create([
    'type' => 'random',
]);

echo "Created random mailbox: {$mailbox->address}\n";

$mailbox = Zemail::mailboxes()->create([
    'type' => 'custom',
    'domain' => 'zemail.me',
    'username' => 'my-inbox',
]);

echo "Created custom mailbox: {$mailbox->address}\n";

$mailbox = Zemail::mailboxes()->get(123);
echo "Address: {$mailbox->address}, Unread emails: {$mailbox->unreadCount}\n";

$deleted = Zemail::mailboxes()->delete(123);
// Returns true on success

// List recent emails with optional search query
$emails = Zemail::mailboxes()->emails()->list(
    mailboxId: $mailbox->id,
    page: 1,
    limit: 25,
    search: 'verification'
);

foreach ($emails->data as $email) {
    echo "[{$email->id}] From: {$email->sender} | Subject: {$email->subject}\n";
}

$email = Zemail::mailboxes()->emails()->get($mailbox->id, $emailId);

echo "Subject: {$email->subject}\n";
echo "Plain text body: {$email->bodyText}\n";
echo "HTML body: {$email->bodyHtml}\n";

// Inspect attachments
foreach ($email->attachments as $attachment) {
    echo "Attachment: {$attachment->name} ({$attachment->size} bytes)\n";
}

$isRead = Zemail::mailboxes()->emails()->markAsRead($mailbox->id, $emailId);

$download = Zemail::mailboxes()->emails()->getAttachmentDownloadUrl(
    mailboxId: $mailbox->id,
    emailId: $emailId,
    attachmentId: 'att_123'
);

echo "Download URL: {$download['url']}\n";
echo "Expires at: {$download['expires_at']}\n";

$deleted = Zemail::mailboxes()->emails()->delete($mailbox->id, $emailId);
// Returns true on success
bash
php artisan vendor:publish --tag="zemail-config"