PHP / Laravel SDK
The official Harbur PHP client library. Compatible with PHP 7.4+ and 8.x, Laravel, WordPress, and Symfony.
PHP 7.4+ & 8.xcomposer: harbur/harburLaravel & WordPress
Installation
bash
composer require harbur/harburBasic Usage
Initialize the client. It automatically detects HARBUR_API_KEY from your environment.
send_email.php
<?php
require_once 'vendor/autoload.php';
use Harbur\Harbur;
// Automatically reads HARBUR_API_KEY from environment
$harbur = new Harbur();
$response = $harbur->emails->send([
'from' => 'support@yourdomain.com',
'to' => 'customer@example.com',
'subject' => 'Welcome to Harbur!',
'html' => '<h1>Welcome aboard!</h1><p>Transactional email sent via PHP.</p>',
'text' => 'Welcome aboard! Transactional email sent via PHP.',
]);
echo "Dispatched Message ID: " . $response['id'] . "\n";Note
Set
HARBUR_API_KEY in your .env file.CC, BCC & Custom Reply-To
advanced.php
<?php
use Harbur\Harbur;
$harbur = new Harbur();
$response = $harbur->emails->send([
'from' => 'support@yourdomain.com',
'to' => ['client@example.com'],
'cc' => ['accounting@example.com'],
'bcc' => ['archive@example.com'],
'reply_to' => 'helpdesk@yourdomain.com',
'subject' => 'Order #1042 Confirmed',
'html' => '<p>Your order is being processed.</p>',
]);File Attachments
Attach PDF invoices or spreadsheets by passing a file path or raw file content.
attachments.php
<?php
use Harbur\Harbur;
$harbur = new Harbur();
$response = $harbur->emails->send([
'from' => 'billing@yourdomain.com',
'to' => 'client@example.com',
'subject' => 'Your Invoice #1042',
'html' => '<p>Your receipt is attached below.</p>',
'attachments' => [
[
'filename' => 'invoice_1042.pdf',
'content' => file_get_contents('invoice.pdf'), // Raw bytes or file path
'content_type' => 'application/pdf',
],
],
]);Laravel Integration
Use the SDK directly inside your Laravel controllers or services:
app/Http/Controllers/OrderController.php
namespace App\Http\Controllers;
use Harbur\Harbur;
use Illuminate\Http\Request;
class OrderController extends Controller
{
public function sendConfirmation(Request $request)
{
$harbur = new Harbur();
$result = $harbur->emails->send([
'from' => 'orders@yourdomain.com',
'to' => $request->user()->email,
'subject' => 'Your Order Confirmation',
'html' => view('emails.order_confirmed')->render(),
]);
return response()->json(['success' => true, 'id' => $result['id']]);
}
}