ActiveCampaign / postmark-php

The official PHP library for Postmark.

Home Page:https://postmarkapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sending multiple emails with a template

vanderwijk opened this issue · comments

Hi, I regularly send reminder emails to a small group of users (max 10) using a template. I use $client->sendEmailWithTemplate for that since the batch email functionality does not seem to support templates.

This is the code I am using:

// Send each recipient the email with template
$recipients =  $_POST[ 'recipients' ];
foreach ( $recipients as $recipient ) {

  // Make a request
  $sendResult = $client->sendEmailWithTemplate(
    "email@example.com",
    $recipient,
    1249561,
    [ "naam_opleiding" => $_POST['naam_opleiding' ],
  ]);

}

Unfortunately, if one of the emails bounces, an error is generated and the foreach loop stops. How can I prevent this?

Hi @vanderwijk,

Have you tried to add a try block inside of your foreach loop?

foreach ( $recipients as $recipient ) {
    try{
      // Make a request
       $sendResult = $client->sendEmailWithTemplate(
       "email@example.com",
       $recipient,
       1249561,
       [ "naam_opleiding" => $_POST['naam_opleiding' ],
    ]);
    }catch($exception){
        //handle exception.
    }
}