0

I had a strange problem with email sending through cakephp and postmark.

I have installed postmark-cakephp library in my cakephp application. I'm able to send email to single user and able to send email to multiple users with same email content (message) but here my requirement is I need to send email to multiple users with some dynamic email content. (contains user id)

I'm able to do this in a for loop but I want to send batch emails with dynamic content with a single call.

Here is my code

foreach($send as $client) {
   //if client contains emails, send email
   if(!empty($client['Email'])) {
      //loop through emails
      foreach($client['Email'] as $to) {
         $client['message'] .= 'To be removed visit http://something.com/remove/'.$to."\n";
        $client['message'] .= $message_footer;
        $email_to = new CakeEmail();
        $email_to->config('postmark');
        $email_to->from('admin@something.com');
        $email_to->to($to);
        $email_to->subject($subject);
        $email_to->send($client['message']);
    }
 }

}

Please help me out.

Buddy
  • 331
  • 3
  • 10
  • Ok I understand but what have you done so far? where is the code? – Fury Aug 27 '15 at 09:25
  • I have updated the query with my sample code. Please check it. – Buddy Aug 27 '15 at 09:49
  • 1
    I don't know how you expect to be able to send multiple emails with _different_ content without some sort of loop somewhere. The solution seems obvious put "I'm able to do this in a for loop" in a method and call it to achieve " I want to send batch emails with dynamic content with a single call." – AD7six Aug 27 '15 at 10:08
  • you can create email templates (different contents) and pass variables to email. – Fury Aug 27 '15 at 13:09

1 Answers1

0

Postmark has a "batch" API feature but it doesn't look like it's supported in the CakePHP lib you're using. There is an official Postmark library which should work ok with Cake but you may have to do a little bit of integration. This library supports the batch API so you can construct all the dynamic messages for individual users and send them in one API call.

JP Toto
  • 1,032
  • 9
  • 10