Skip to content

Sending Batches

Andrew Theken edited this page May 15, 2017 · 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.

// 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);
}

Clone this wiki locally