-
Notifications
You must be signed in to change notification settings - Fork 53
Sending Batches
CharlieSears edited this page Feb 6, 2019
·
8 revisions
The Postmark batch API allows you to send up to 500 messages at a time. To do so, create messages that follow the same names as outlined in the Postmark developer documentation.
Please note that the /batch
endpoint will return a 200-level http status, even when validation for individual messages may fail. Users of these endpoints should check the success and error code for each message in the response from our API (the results are ordered the same as the original messages).
// If you are using composer, vendor/autoload.php will be at the root of your project.
// Take note of this path and make sure it's relative to the script when you run it.
require_once('./vender/autoload.php');
use Postmark\PostmarkClient;
//Create messages that follow the JSON naming convention
//referenced above.
$message1 = ['To' => "someone@someplace.com",
'Cc' => "someoneelse@someplace.com",
'Subject' => "Message 1",
'TextBody' =>"Some plain text",
'From' => "you@yourdomain.com"];
$message2 = ['To' => "someone@someplace.com",
'Cc' => "someoneelse@someplace.com",
'Subject' => "Message 1",
'HtmlBody' =>"<b>HELLO!</b>",
'From' => "you@yourdomain.com"];
$newClient = new PostmarkClient("server_token");
//Pass the messages as an array to the `sendEmailBatch` function.
$responses = $newClient->sendEmailBatch([$message1, $message2]);
// The response from the batch API returns an array of responses for each
// message sent. You can iterate over it to get the individual results of sending.
foreach($responses as $key=>$response){
var_dump($response);
}
The Postmark-PHP client can be installed from Packagist.
For additional information about the capabilities of the Postmark API, see Postmark Developers Documentation.