PHP code example of ankitfromindia / parallel-smtp

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

    

ankitfromindia / parallel-smtp example snippets


use AnkitFromIndia\ParallelSmtp\Http\ParallelSmtpClient;

class BulkEmailService
{
    public function sendCampaign(array $recipients)
    {
        $client = app(ParallelSmtpClient::class);
        
        $messages = [];
        foreach ($recipients as $recipient) {
            $messages[] = [
                'from' => '[email protected]',
                'to' => $recipient['email'],
                'subject' => 'Welcome to Our Newsletter',
                'body' => view('emails.welcome', $recipient)->render(),
                'content_type' => 'text/html'
            ];
        }
        
        $results = $client->sendBulk($messages);
        
        return $this->processResults($results);
    }
    
    private function processResults(array $results): array
    {
        $stats = ['sent' => 0, 'failed' => 0, 'errors' => []];
        
        foreach ($results as $index => $result) {
            if ($result['success']) {
                $stats['sent']++;
            } else {
                $stats['failed']++;
                $stats['errors'][] = "Message {$index}: {$result['error']}";
            }
        }
        
        return $stats;
    }
}

$messages = [
    [
        'from' => '[email protected]',
        'to' => '[email protected]',
        'cc' => ['[email protected]', '[email protected]'],
        'bcc' => ['[email protected]'],
        'subject' => 'Important Update',
        'body' => '<h1>Update Notification</h1><p>Content here...</p>',
        'content_type' => 'text/html'
    ]
];

$client = app(ParallelSmtpClient::class);
$results = $client->sendBulk($messages);

$results = $client->sendBulk($messages);

foreach ($results as $index => $result) {
    if ($result['success']) {
        echo "✅ Email {$index}: Sent successfully\n";
    } else {
        echo "❌ Email {$index}: {$result['error']}\n";
    }
}
bash
php artisan vendor:publish --tag=parallel-smtp-config