https://github.com/postalserver/postal-php
A PHP library for the Postal e-mail platform
https://github.com/postalserver/postal-php
Last synced: about 1 year ago
JSON representation
A PHP library for the Postal e-mail platform
- Host: GitHub
- URL: https://github.com/postalserver/postal-php
- Owner: postalserver
- Created: 2017-04-20T15:25:59.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T13:19:42.000Z (over 1 year ago)
- Last Synced: 2025-04-02T08:01:41.916Z (about 1 year ago)
- Language: PHP
- Size: 34.2 KB
- Stars: 72
- Watchers: 7
- Forks: 27
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Postal for PHP
This library helps you send e-mails through [Postal](https://github.com/postalserver/postal) in PHP 7.4 and above.
## Installation
Install the library using [Composer](https://getcomposer.org/):
```
$ composer require postal/postal
```
## Usage
Sending an email is very simple. Just follow the example below. Before you can begin, you'll
need to login to our web interface and generate a new API credential.
```php
// Create a new Postal client using the server key you generate in the web interface
$client = new Postal\Client('https://postal.yourdomain.com', 'your-api-key');
// Create a new message
$message = new Postal\Send\Message();
// Add some recipients
$message->to('john@example.com');
$message->to('mary@example.com');
$message->cc('mike@example.com');
$message->bcc('secret@awesomeapp.com');
// Specify who the message should be from. This must be from a verified domain
// on your mail server.
$message->from('test@test.postal.io');
// Set the subject
$message->subject('Hi there!');
// Set the content for the e-mail
$message->plainBody('Hello world!');
$message->htmlBody('
Hello world!
');
// Add any custom headers
$message->header('X-PHP-Test', 'value');
// Attach any files
$message->attach('textmessage.txt', 'text/plain', 'Hello world!');
// Send the message and get the result
$result = $client->send->message($message);
// Loop through each of the recipients to get the message ID
foreach ($result->recipients() as $email => $message) {
$email; // The e-mail address of the recipient
$message->id; // The message ID
$message->token; // The message's token
}
```