sendEmailBatch() 공개 메소드

Each email is an associative array of values, but note that the 'Attachments' key must be an array of 'PostmarkAttachment' objects if you intend to send attachments with an email.
public sendEmailBatch ( array $emailBatch = [] ) : Postmark\Models\DynamicResponseModel
$emailBatch array An array of emails to be sent in one batch.
리턴 Postmark\Models\DynamicResponseModel
 function testClientCanSendBatchMessages()
 {
     $tk = parent::$testKeys;
     $currentTime = date("c");
     $batch = array();
     $attachment = PostmarkAttachment::fromRawData("attachment content", "hello.txt", "text/plain");
     for ($i = 0; $i < 5; $i++) {
         $payload = array('From' => $tk->WRITE_TEST_SENDER_EMAIL_ADDRESS, 'To' => $tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS, 'Subject' => "Hello from the PHP Postmark Client Tests! ({$currentTime})", 'HtmlBody' => '<b>Hi there! (batch test)</b>', 'TextBody' => 'This is a text body for a test email.', 'TrackOpens' => true, 'Headers' => array("X-Test-Header" => "Test Header Content", 'X-Test-Date-Sent' => date('c')), 'Attachments' => array($attachment));
         $batch[] = $payload;
     }
     $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $response = $client->sendEmailBatch($batch);
     $this->assertNotEmpty($response, 'The client could not send a batch of messages.');
 }
예제 #2
0
 public function index2Action($maker_id = null)
 {
     if ($maker_id != null) {
         $maker_id = $this->filter->sanitize($maker_id, 'int');
         if ($maker = PMaker::findFirst($maker_id)) {
             $this->view->products = $products = PProductMain::find("maker_id={$maker_id}");
             $this->view->maker = $maker;
             $this->view->count = PProductMain::count("maker_id={$maker_id}");
             if ($this->request->isPost()) {
                 $args = ['main_comment' => ['filter' => FILTER_SANITIZE_STRING], 'title' => ['filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY], 'oldprice' => ['filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'flags' => FILTER_REQUIRE_ARRAY], 'comment' => ['filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY]];
                 $inpData = filter_input_array(INPUT_POST, $args);
                 $main_comment = $inpData['main_comment'];
                 $title = $inpData['title'];
                 $oldprice = $inpData['oldprice'];
                 $comment = $inpData['comment'];
                 $body = "";
                 if (!empty($main_comment)) {
                     $body = "Комментарий: {$main_comment}<br><br>";
                 }
                 $body .= "<table width='100%' border='1' cellpadding='2' cellspacing='1'>";
                 $body .= "<tr><td>ID</td><td>Название</td><td>Старая цена</td><td>Комментарий</td></tr>";
                 foreach ($comment as $product_id => $value) {
                     if (!$value) {
                         continue;
                     }
                     $body .= "<tr>\n                        <td>{$product_id}</td>\n                        <td>{$title[$product_id]}</td>\n                        <td>{$oldprice[$product_id]} {$maker->currencystr}</td>\n                        <td>{$value}</td>\n                      </tr>";
                 }
                 $body .= "</table>";
                 // Compose a message
                 $msg = ['To' => $this->config->emails->usercab2, 'From' => $this->config->POSTMARK->POSTMARK_FROM, 'Subject' => "Комментарии от мастера - {$maker->name}", 'HtmlBody' => "<html><body>{$body}</body></html>"];
                 try {
                     $client = new PostmarkClient($this->config->POSTMARK->POSTMARK_API);
                     $send = $client->sendEmailBatch([$msg]);
                     $this->flash->success('Сохранено!');
                 } catch (PostmarkException $ex) {
                     if ($ex) {
                         $this->flash->error('Произошла ошибка!');
                     }
                 }
             }
         } else {
             $this->flash->error('Мастер с таким ID не найден!');
             $this->response->redirect('usercab/index2');
         }
     }
 }
예제 #3
0
<?php

// Preparation
require_once './vendor/autoload.php';
use Postmark\Models\PostmarkAttachment;
use Postmark\PostmarkClient;
//function sendBatchOfEmails(){
$attachment = PostmarkAttachment::fromFile(dirname(__FILE__) . '/test.jpg', 'attachment-file-name.jpg', image / jpg);
//$TussenArray = $_POST;
//$message = $_POST;
$message = array('To' => "*****@*****.**", 'From' => "*****@*****.**", 'Cc' => "*****@*****.**", 'Subject' => "Test", 'TextBody' => "Dit is een testmail, ik hoop dat het nu eindelijk werkt.", 'Attachments' => $attachment);
$client = new PostmarkClient("f92ee11a-3de9-48ff-801e-1b6efc9afcdf");
$sendResult = $client->sendEmailBatch($message);
// Did it send successfully?
if ($sendResult != null) {
    echo 'The email was sent!';
} else {
    echo 'The email could not be sent!';
}
//}
예제 #4
0
 /**
  * Help request
  *
  * @Post("/help")
  */
 public function helpAction()
 {
     //        $this->view->disable();
     if ($this->request->isAjax()) {
         $email = $this->request->get("email", 'email');
         $question = $this->request->get("question", 'string');
         $status = 1;
         try {
             $client = new PostmarkClient($this->config->POSTMARK->POSTMARK_API);
             // 'To'       => $this->strings->help_manager_email,
             $html = $this->simple_view->render('mail/_help_template', ['strings' => $this->strings, 'mail' => $email, 'question' => $question]);
             $message = ['To' => "", 'From' => $this->config->POSTMARK->POSTMARK_FROM, 'Subject' => $this->strings->help_request, 'HtmlBody' => $html];
             $send = $client->sendEmailBatch([$message]);
         } catch (PostmarkException $ex) {
             if ($ex) {
                 $status = 0;
             }
         }
         echo $status;
     }
 }
예제 #5
0
    public function moderAction()
    {
        $stats = [];
        $stats['done'] = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id']);
        $stats['done_hold'] = PStats::count(["coder_status = 5 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['inmoder'] = PProdInfo::count(["coder_status = 3", 'group' => 'lang', 'order' => 'id']);
        $stats['inmoder_hold'] = PStats::count(["coder_status = 3 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['returned'] = PProdInfo::count(["coder_status = 6", 'group' => 'lang', 'order' => 'id']);
        $stats['returned_hold'] = PStats::count(["coder_status = 6 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['todo_hold'] = PStats::count(["coder_status < 3 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['hold_total'] = PStats::count(["hold = 1", 'group' => 'lang', 'order' => 'id']);
        $langs = PProdInfo::count(['group' => 'lang', 'order' => 'id']);
        $total_ru = PStats::count("coder_status = 5 AND lang = 'ru'");
        $total = PProductMain::count();
        $date = date('d.m.Y');
        $titles = ["Сделано (5) (из них на холде)", "На модерации (3) (из них на холде)", "Возвращено (6) (из них на холде)", "Не обработано еще (0) (из них на холде)", "Замороженые товары (hold), всего"];
        $stat_titles = ["done", "inmoder", "returned"];
        $text = <<<TEXT
<p style="margin-bottom: 20px">Всего товаров: <span id="total">{$total}</span></p>
<p style="margin-bottom: 20px">Отчет на {$date}</p>
<table border='1'>
<tr>
<th></th>
TEXT;
        foreach ($langs as $lang => $stat) {
            $text .= "<th width='110px'>{$stat['lang']}</th>";
        }
        $text .= "</tr>";
        for ($i = 0; $i < 3; $i++) {
            $text .= "<tr><td>{$titles[$i]}</td>";
            foreach ($langs as $lang => $stat) {
                $text .= "<td>";
                foreach ($stats[$stat_titles[$i]] as $lang_total => $stat_total) {
                    if ($stat_total['lang'] == $stat['lang']) {
                        $text .= $stat_total['rowcount'] . " ";
                        foreach ($stats[$stat_titles[$i] . '_hold'] as $lang_hold => $stat_hold) {
                            if ($stat_hold['lang'] == $stat['lang']) {
                                $text .= "({$stat_hold['rowcount']})";
                            }
                        }
                    }
                }
                $text .= "</td>";
            }
            $text .= "</tr>";
        }
        $text .= "<tr><td>{$titles[3]}</td>";
        foreach ($langs as $lang => $stat) {
            $text .= "<td>";
            if ($stat['lang'] == 'ru') {
                $text .= $total - $stat['rowcount'];
            } else {
                $text .= $total_ru - $stat['rowcount'];
            }
            foreach ($stats['todo_hold'] as $lang_hold => $stat_hold) {
                if ($stat_hold['lang'] == $stat['lang']) {
                    $text .= "({$stat_hold['rowcount']})";
                }
            }
            $text .= "</td>";
        }
        $text .= "</tr>";
        $text .= "<tr><td>{$titles[4]}</td>";
        foreach ($langs as $lang => $stat) {
            $text .= "<td>";
            foreach ($stats['hold_total'] as $lang_hold => $stat_hold) {
                if ($stat_hold['lang'] == $stat['lang']) {
                    $text .= "{$stat_hold['rowcount']}";
                }
            }
            $text .= "</td>";
        }
        $text .= "</tr></table>";
        $text .= <<<TEXT
<br><br><b>Описание</b>
<p>Сделано (5) - товары со статусом перевода на данный язык == 5 ( в случае с RU статус копирайта == 5)</p>
<p>На модерации (3) - товары со статусом перевода на данный язык == 3 ( в случае с RU статус копирайта == 3)</p>
<p>Возвращено (6) - товары со статусом перевода на данный язык == 6 ( в случае с RU статус копирайта == 6)</p>
<p>Не обработано еще (0) - товары со статусом перевода на данный язык == 0 ( в случае с RU статус копирайта == 0)</p>
<p>Замороженые товары (hold) - товары со статусом hold == Да</p>
TEXT;
        $message[] = ['To' => '*****@*****.**', 'From' => POSTMARK_FROM, 'Subject' => "Количество отмодерированных товаров. Отчет за {$date}", 'HtmlBody' => $text];
        $client = new PostmarkClient(POSTMARK_API);
        //        var_dump($message);
        $send = $client->sendEmailBatch($message);
    }