AmazonSesClient
in package
Amazon SES email client wrapper class.
Provides fluent interface for sending emails via AWS Simple Email Service with support for XML-based templates, CC/BCC recipients, and configuration sets.
use \X\Util\AmazonSesClient;
$ses = new AmazonSesClient([
'region' => $_ENV['AMS_SES_REGION'],
'credentials' => [
'key' => $_ENV['AMS_SES_ACCESS_KEY'],
'secret' => $_ENV['AMS_SES_SECRET_KEY']
],
'configuration' => $_ENV['AMS_SES_CONFIGURATION'],
]);
$ses
->from('from@example.com')
->to('to@example.com')
->messageFromXml('email/sample', ['name' => 'Alex'])
->send();
Email body and subject: application/views/email/sample.xml.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mail>
<subject>Test email.</subject>
<message>
Hi {{ name }}.
</message>
</mail>
Table of Contents
Properties
- $bcc : string
- BCC email address.
- $cc : string
- CC email address.
- $charset : string
- Character code of the email. Default is "UTF-8".
- $from : string
- Sender's email address.
- $fromName : string
- Sender name.
- $message : string
- Body.
- $options : array<string|int, mixed>
- SES client options.
- $subject : string
- Subject.
- $to : string
- Destination email address.
Methods
- __construct() : mixed
- Initialize AmazonSesClient.
- bcc() : AmazonSesClient
- Set BCC recipient address.
- cc() : AmazonSesClient
- Set CC recipient address.
- charset() : AmazonSesClient
- Set the email character encoding.
- from() : AmazonSesClient
- Set the sender address.
- message() : AmazonSesClient
- Set the email body text.
- messageFromXml() : AmazonSesClient
- Set subject and body from an XML template.
- send() : Result
- Send the email via Amazon SES.
- subject() : AmazonSesClient
- Set the email subject line.
- to() : AmazonSesClient
- Set the recipient address.
- client() : SesClient
- Get or create singleton SES client instance.
- reset() : void
- Reset all message fields to defaults.
Properties
$bcc
BCC email address.
private
string
$bcc
= null
$cc
CC email address.
private
string
$cc
= null
$charset
Character code of the email. Default is "UTF-8".
private
string
$charset
= 'UTF-8'
$from
Sender's email address.
private
string
$from
= null
$fromName
Sender name.
private
string
$fromName
= null
$message
Body.
private
string
$message
= null
$options
SES client options.
private
array<string|int, mixed>
$options
= null
- credentials: array with 'key' and 'secret' for AWS credentials
- configuration: string|null configuration set name
- region: string AWS region (e.g., 'ap-northeast-1')
- version: string API version (default: 'latest')
$subject
Subject.
private
string
$subject
= null
$to
Destination email address.
private
string
$to
= null
Methods
__construct()
Initialize AmazonSesClient.
public
__construct([array{credentials?: array{key: string, secret: string}, configuration?: string|null, region?: string, version?: string} $options = [] ]) : mixed
Parameters
- $options : array{credentials?: array{key: string, secret: string}, configuration?: string|null, region?: string, version?: string} = []
-
Configuration options:
-
credentials.key: AWS access key ID. -
credentials.secret: AWS secret access key. -
configuration: SES configuration set name. Default is null. -
region: AWS region for service requests. -
version: SES API version. Default is "latest".
-
bcc()
Set BCC recipient address.
public
bcc(string|array<string|int, string> $bcc) : AmazonSesClient
Parameters
- $bcc : string|array<string|int, string>
-
BCC email address or array of addresses.
Return values
AmazonSesClient —Method chaining.
cc()
Set CC recipient address.
public
cc(string|array<string|int, string> $cc) : AmazonSesClient
Parameters
- $cc : string|array<string|int, string>
-
CC email address or array of addresses.
Return values
AmazonSesClient —Method chaining.
charset()
Set the email character encoding.
public
charset(string $charset) : AmazonSesClient
Parameters
- $charset : string
-
Character encoding (e.g., "UTF-8", "ISO-2022-JP").
Return values
AmazonSesClient —Method chaining.
from()
Set the sender address.
public
from(string $from[, string|null $fromName = null ]) : AmazonSesClient
Parameters
- $from : string
-
Sender's email address.
- $fromName : string|null = null
-
Display name for the sender.
Return values
AmazonSesClient —Method chaining.
message()
Set the email body text.
public
message(string $message) : AmazonSesClient
Parameters
- $message : string
-
Email body content.
Return values
AmazonSesClient —Method chaining.
messageFromXml()
Set subject and body from an XML template.
public
messageFromXml(string $xmlPath[, array<string|int, mixed> $params = [] ]) : AmazonSesClient
The XML file should contain <subject> and <message> elements.
Twig variables can be used in the template.
Parameters
- $xmlPath : string
-
XML template path relative to
application/views/. - $params : array<string|int, mixed> = []
-
Template variables for interpolation.
Return values
AmazonSesClient —Method chaining.
send()
Send the email via Amazon SES.
public
send() : Result
After sending, all recipient and message fields are reset.
Tags
Return values
Result —SES API response containing MessageId.
subject()
Set the email subject line.
public
subject(string $subject) : AmazonSesClient
Parameters
- $subject : string
-
Subject text.
Return values
AmazonSesClient —Method chaining.
to()
Set the recipient address.
public
to(string|array<string|int, string> $to) : AmazonSesClient
Parameters
- $to : string|array<string|int, string>
-
Recipient email address or array of addresses.
Return values
AmazonSesClient —Method chaining.
client()
Get or create singleton SES client instance.
private
client() : SesClient
Return values
SesClient —Cached SES client instance.
reset()
Reset all message fields to defaults.
private
reset() : void