Download the PHP package dealnews/aws-ses without Composer
On this page you can find all versions of the php package dealnews/aws-ses. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dealnews/aws-ses
More information about dealnews/aws-ses
Files in dealnews/aws-ses
Package aws-ses
Short Description A fluent wrapper for AWS SES email sending
License BSD-3-Clause
Informations about the package aws-ses
dealnews/aws-ses
A fluent PHP wrapper around the AWS SDK's SES v2 client for sending email — build a message with a chainable API, send it, and get back a typed result. No raw AWS SDK arrays to hand-assemble, no MIME to build by hand.
Features
- Fluent message builder — chain
from(),to(),subject(),html(),attach(), and more to build up an email. - Attachments, without MIME wrangling — attach files (raw bytes or by path) and the library sends them through SES v2's native attachment support, no manual multipart/MIME construction required.
- Custom headers — add arbitrary headers (e.g.
X-headers) to outgoing mail. - Fails fast — invalid email addresses and missing required fields (from, recipient, subject, body) throw immediately, before anything is sent to AWS.
- Typed exceptions — a single interface (
AwsSesExceptionInterface) to catch anything this library throws, with distinct exception types for build-time validation errors vs. send-time AWS failures. - Typed result object —
send()returns aSendResultvalue object (message ID, HTTP status, request ID), not a raw AWSResult/array. - Bring your own client — you construct and configure the
Aws\SesV2\SesV2Client(region, credentials, etc.); this library just builds the request and sends it, which also makes it trivial to test against with a mocked client.
Installation
Requires PHP 8.2+ and aws/aws-sdk-php (installed automatically as a
dependency).
You'll also need AWS credentials configured wherever this runs (environment
variables, an IAM instance/task role, a shared credentials file, etc.) with
permission to call ses:SendEmail, and a verified sending identity
(domain or email address) in SES.
Quick Start
Usage Examples
Multiple recipients
Call to(), cc(), bcc(), or replyTo() once per address — each call
appends a recipient rather than replacing the list:
Attachments
Attach raw bytes directly, or read a file from disk:
attachFromPath() defaults the recipient-facing filename to the source
file's basename and detects the content type from the file itself; both can
be overridden with the second and third arguments.
Custom headers and configuration sets
Handling errors
API Overview
DealNews\AwsSes\Message
The fluent builder used to describe an email. All setters return $this,
so calls chain. Getters (getFrom(), getTo(), etc.) are also available if
you need to inspect a message you've built.
| Method | Description |
|---|---|
from(string $email, ?string $name = null) |
Sets the sender address. |
to(string $email, ?string $name = null) |
Appends a "to" recipient. Call once per recipient. |
cc(string $email, ?string $name = null) |
Appends a "cc" recipient. |
bcc(string $email, ?string $name = null) |
Appends a "bcc" recipient. |
replyTo(string $email, ?string $name = null) |
Appends a "reply-to" address. |
subject(string $subject) |
Sets the subject line. |
text(string $body) |
Sets the plain text body. |
html(string $body) |
Sets the HTML body. |
attach(string $content, string $filename, string $content_type = 'application/octet-stream') |
Appends an attachment from raw content. |
attachFromPath(string $path, ?string $filename = null, ?string $content_type = null) |
Appends an attachment read from disk. |
header(string $name, string $value) |
Adds a custom email header. |
configurationSetName(string $name) |
Sets the SES configuration set to send under. |
charset(string $charset) |
Sets the charset for the subject/body (default UTF-8). |
hasAttachments(): bool |
Whether one or more attachments have been added. |
validate(): void |
Throws MissingRequiredFieldException if a required field (from, at least one recipient, subject, a text or HTML body) is missing. Called automatically by Mailer::send(). |
A Message requires, at minimum, a from, at least one recipient
(to/cc/bcc), a subject, and a text and/or html body.
DealNews\AwsSes\Mailer
Wraps a configured Aws\SesV2\SesV2Client. send() validates the message,
builds the SES v2 SendEmail request (envelope from Message, Content
from EmailContentBuilder), and returns a SendResult. Any exception from
the AWS SDK is caught and rethrown as SendException, with the original
exception available via getPrevious().
The second constructor argument is mainly useful for testing or advanced
customization — the default EmailContentBuilder is used if you don't pass
one.
DealNews\AwsSes\EmailContentBuilder
Builds the Content parameter of the SES v2 SendEmail request from a
Message. Always builds Content.Simple — subject, body, and (when
present) Headers and Attachments — since SES v2's Simple content
natively supports both. You generally won't call this directly; Mailer
does it for you.
DealNews\AwsSes\SendResult
Returned by Mailer::send() on success.
DealNews\AwsSes\Address, Header, Attachment
Small value objects used internally and returned from Message's getters.
Address::__construct(string $email, ?string $name = null)validates the email immediately (throwsInvalidAddressExceptionif invalid), and exposesgetEmail(),getName(), andtoString()(renders as"Name <email>"or bare"email").Header::__construct(string $name, string $value)exposesgetName()andgetValue().Attachment::__construct(string $filename, string $content, string $content_type = 'application/octet-stream')exposesgetFilename(),getContent(),getContentType(), and the static factoryAttachment::fromPath(string $path, ?string $filename = null, ?string $content_type = null).
Exceptions (DealNews\AwsSes\Exception)
| Exception | Thrown when |
|---|---|
AwsSesExceptionInterface |
(marker interface, not thrown directly) — implemented by every exception below, so you can catch any of them at once. |
ValidationException |
Base class for all build-time validation errors below. Extends \InvalidArgumentException. |
InvalidAddressException |
An email passed to from()/to()/cc()/bcc()/replyTo() fails validation. |
MissingRequiredFieldException |
Message::validate() finds a missing required field. |
AttachmentException |
Attachment::fromPath() can't read the given file. |
SendException |
The AWS SDK throws while calling SendEmail. Extends \RuntimeException; the original exception is available via getPrevious(). |
Testing
Run the test suite:
This runs parallel-lint followed by PHPUnit (with coverage). Individual
tools are also available directly:
Tests never make real AWS calls — Aws\SesV2\SesV2Client is constructed
with an Aws\MockHandler that intercepts requests and returns canned
responses. If you're testing code that uses this library, the same
approach works well:
To assert on the request that would have been sent, append a closure
instead of a Result — it receives the Aws\CommandInterface and must
return the Result to respond with:
Code Style
This repo uses php-cs-fixer (config in .php-cs-fixer.dist.php):
License
BSD-3-Clause. See the license field in composer.json.