Skip to content

PHP

Latest Version Build Status License: MIT

PHP SDK for the Poodle’s email sending API.

Install the SDK using Composer:

Terminal window
composer require usepoodle/poodle-php
<?php
require_once 'vendor/autoload.php';
use Poodle\PoodleClient;
// Initialize the client
$client = new PoodleClient('your_api_key_here');
// Send an email
$response = $client->send(
subject: 'Hello from Poodle!',
html: '<h1>Hello World!</h1><p>This is a test email.</p>',
text: 'Hello World! This is a test email.'
);
echo "Email sent! Message: " . $response->getMessage();
  • Simple and intuitive API
  • HTML and plain text email support
  • Comprehensive error handling
  • Built-in input validation
  • PSR-12 compliant code
  • 100% type coverage with PHPDoc
  • Extensive test suite
  • PHP 8.0+ support

Set your API key in one of these ways:

1. Pass directly to constructor:

$client = new PoodleClient('your_api_key_here');

2. Use environment variable:

Terminal window
export POODLE_API_KEY=your_api_key_here
$client = new PoodleClient(); // Will use POODLE_API_KEY

3. Use Configuration object:

use Poodle\Configuration;
$config = new Configuration(
apiKey: 'your_api_key_here',
baseUrl: 'https://api.usepoodle.com',
timeout: 30.0,
debug: true
);
$client = new PoodleClient($config);
VariableDefaultDescription
POODLE_API_KEY-Your Poodle API key
POODLE_BASE_URLhttps://api.usepoodle.comAPI base URL
POODLE_TIMEOUT30.0Request timeout in seconds
POODLE_CONNECT_TIMEOUT10.0Connection timeout in seconds
POODLE_DEBUGfalseEnable debug logging
use Poodle\PoodleClient;
$client = new PoodleClient('your_api_key');
// HTML email
$response = $client->sendHtml(
subject: 'Welcome!',
html: '<h1>Welcome to our service!</h1>'
);
// Plain text email
$response = $client->sendText(
subject: 'Welcome!',
text: 'Welcome to our service!'
);
use Poodle\Model\Email;
use Poodle\PoodleClient;
$client = new PoodleClient('your_api_key');
// Create email object
$email = new Email(
subject: 'Welcome Email',
html: '<h1>Hello!</h1><p>Welcome to our service!</p>',
text: 'Hello! Welcome to our service!'
);
// Send the email
$response = $client->sendEmail($email);
if ($response->isSuccessful()) {
echo "Email queued successfully!";
}
use Poodle\PoodleClient;
use Poodle\Exception\ValidationException;
use Poodle\Exception\AuthenticationException;
use Poodle\Exception\RateLimitException;
use Poodle\Exception\NetworkException;
use Poodle\Exception\PoodleException;
$client = new PoodleClient('your_api_key');
try {
$response = $client->send(
subject: 'Test Email',
html: '<h1>Hello!</h1>'
);
echo "Email sent successfully!";
} catch (ValidationException $e) {
echo "Validation error: " . $e->getMessage() . "\n";
foreach ($e->getErrors() as $field => $errors) {
echo " {$field}: " . implode(', ', $errors) . "\n";
}
} catch (AuthenticationException $e) {
echo "Authentication failed: " . $e->getMessage() . "\n";
} catch (RateLimitException $e) {
echo "Rate limit exceeded. Retry after: " . $e->getRetryAfter() . " seconds\n";
} catch (NetworkException $e) {
echo "Network error: " . $e->getMessage() . "\n";
} catch (PoodleException $e) {
echo "Poodle error: " . $e->getMessage() . "\n";
echo "Context: " . json_encode($e->getContext()) . "\n";
}

For more usage patterns, see the examples directory.

The main client class for sending emails.

new PoodleClient(string|Configuration $apiKeyOrConfig, ?string $baseUrl = null)
  • send(string $from, string $to, string $subject, ?string $html = null, ?string $text = null): EmailResponse
  • sendHtml(string $from, string $to, string $subject, string $html): EmailResponse
  • sendText(string $from, string $to, string $subject, string $text): EmailResponse
  • sendEmail(Email|array $email): EmailResponse

Represents an email to be sent.

new Email(string $from, string $to, string $subject, ?string $html = null, ?string $text = null)
  • getFrom(): string - Get sender email address
  • getTo(): string - Get recipient email address
  • getSubject(): string - Get email subject
  • getHtml(): ?string - Get HTML content
  • getText(): ?string - Get plain text content
  • toArray(): array - Convert to array for API request

Represents the API response after sending an email.

  • isSuccessful(): bool - Check if email was successfully queued
  • getMessage(): string - Get response message
  • toArray(): array - Convert to array
  • toJson(): string - Convert to JSON

SDK configuration object.

new Configuration(
?string $apiKey = null,
?string $baseUrl = null,
?float $timeout = null,
?float $connectTimeout = null,
bool $debug = false,
array $httpClientOptions = []
)

Add to your .env:

POODLE_API_KEY=your_api_key_here

Create a service:

app/Services/EmailService.php
use Poodle\PoodleClient;
class EmailService
{
private PoodleClient $client;
public function __construct()
{
$this->client = new PoodleClient(config('services.poodle.api_key'));
}
public function sendWelcomeEmail(string $email, string $name): void
{
$this->client->sendHtml(
to: $email,
subject: "Welcome, {$name}!",
html: view('emails.welcome', compact('name'))->render()
);
}
}
config/services.yaml
services:
Poodle\PoodleClient:
arguments:
$apiKeyOrConfig: "%env(POODLE_API_KEY)%"
Terminal window
# Install dependencies
composer install
# Run tests
composer test
# Run tests with coverage
composer test-coverage
# Code style check
composer cs-check
# Fix code style
composer cs-fix
# Static analysis
composer phpstan
  • PHP 7.4 or higher
  • ext-json
  • GuzzleHTTP 7.0+
HTTP CodeExceptionDescription
400ValidationExceptionInvalid request data
401AuthenticationExceptionInvalid or missing API key
403AuthenticationExceptionInsufficient permissions
408NetworkExceptionRequest timeout
429RateLimitExceptionRate limit exceeded
5xxNetworkExceptionServer error

Contributions are welcome! Please read our Contributing Guide for details on the process for submitting pull requests and our Code of Conduct.

This project is licensed under the MIT License - see the LICENSE file for details.