PHP code example of shoutboxnet / shoutbox

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

    

shoutboxnet / shoutbox example snippets




// Your API key from Shoutbox.net
$apiKey = 'your-api-key-here';

// Prepare email data
$data = [
    'from' => '[email protected]',
    'to' => '[email protected]',
    'subject' => 'Test Email',
    'html' => '<h1>Hello!</h1><p>This is a test email.</p>',
    'name' => 'Sender Name',
    'reply_to' => '[email protected]'
];

// Make the API call
$ch = curl_init('https://api.shoutbox.net/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// Handle the response
if ($httpCode >= 200 && $httpCode < 300) {
    echo "Email sent successfully!\n";
} else {
    echo "Failed to send email. Status code: $httpCode\n";
}



houtbox\Client;
use Shoutbox\EmailOptions;
use Shoutbox\Attachment;

// Initialize client
$apiKey = getenv('SHOUTBOX_API_KEY') ?: 'your-api-key-here';
$client = new Client($apiKey);

try {
    // Basic email
    $options = new EmailOptions();
    $options->from = '[email protected]';
    $options->to = '[email protected]';
    $options->subject = 'Test Email';
    $options->html = '<h1>Hello!</h1><p>This is a test email.</p>';
    $options->name = 'Sender Name';
    $options->replyTo = '[email protected]';

    $client->sendEmail($options);

    // Email with attachment
    $attachment = new Attachment();
    $attachment->filepath = './document.pdf';
    $attachment->filename = 'document.pdf';
    $attachment->contentType = 'application/pdf';

    $optionsWithAttachment = new EmailOptions();
    $optionsWithAttachment->from = '[email protected]';
    $optionsWithAttachment->to = '[email protected]';
    $optionsWithAttachment->subject = 'Test Email with Attachment';
    $optionsWithAttachment->html = '<h1>Hello!</h1><p>This email 



houtbox\SMTPClient;
use Shoutbox\EmailOptions;

$client = new SMTPClient('your-api-key-here');

try {
    // Multiple recipients
    $options = new EmailOptions();
    $options->from = '[email protected]';
    $options->to = ['[email protected]', '[email protected]'];
    $options->subject = 'Test Email';
    $options->html = '<h1>Hello!</h1><p>This is a test email.</p>';
    $options->headers = [
        'X-Custom-Header' => 'Custom Value',
        'X-Priority' => '1'
    ];

    $client->sendEmail($options);

} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

'shoutbox' => [
    'key' => env('SHOUTBOX_API_KEY'),
],

use Illuminate\Support\Facades\Mail;

Mail::to('[email protected]')
    ->send(new ShoutboxMail('<h1>Hello</h1><p>This is a test email.</p>'));

Mail::to('[email protected]')
    ->from('[email protected]', 'Sender Name')
    ->replyTo('[email protected]')
    ->cc(['[email protected]', '[email protected]'])
    ->send(new ShoutboxMail('<h1>Hello</h1><p>This is a test email.</p>'));

class SendEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        Mail::to('[email protected]')
            ->send(new ShoutboxMail('<h1>Hello</h1><p>This is a queued email.</p>'));
    }
}