상속: extends PostmarkClientBase
 function testClientCanGetClickLocationStatistics()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->READ_LINK_TRACKING_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $stats = $client->getOutboundClickLocationStatistics();
     $this->assertNotNull($stats);
 }
 function testClientCanGetOutboundReadTimeStatistics()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->READ_SELENIUM_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $stats = $client->getOutboundReadTimeStatistics();
     $this->assertNotEmpty($stats);
 }
 function testClientCanGetBounceTags()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->READ_INBOUND_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $tags = $client->getBounceTags();
     $this->assertNotEmpty($tags);
     $this->assertGreaterThan(0, count($tags));
 }
 function testClientCanCreateAndDeleteRuleTriggers()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $trigger = $client->createInboundRuleTrigger('test.php+' . uniqid("", true) . '@example.com');
     $this->assertNotEmpty($trigger);
     $client->deleteInboundRuleTrigger($trigger->ID);
     //Not throwing an exception here constitutes passing.
 }
 function testClientCanGetOutboundMessageDump()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->READ_SELENIUM_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $retrievedMessages = $client->getOutboundMessages(1, 50);
     $baseMessageId = $retrievedMessages->Messages[0]["MessageID"];
     $message = $client->getOutboundMessageDump($baseMessageId);
     $this->assertNotEmpty($message);
 }
 function testClientCanEditServerInformation()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $originalServer = $client->getServer();
     $server = $client->editServer('testing-server-' . date('c'));
     //set it back to the original name.
     $client->editServer($originalServer->Name);
     $this->assertNotSame($originalServer->Name, $server->Name);
 }
 function testClientCanEditExistingTagTriggers()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $trigger = $client->createTagTrigger(uniqid("PHP-TEST-", true), false);
     $updatedTrigger = $client->editTagTrigger($trigger->ID, uniqid("PHP-TEST-", true), true);
     $this->assertNotSame($trigger->MatchName, $updatedTrigger->MatchName);
     $this->assertNotSame($trigger->TrackOpens, $updatedTrigger->TrackOpens);
     $client->deleteTagTrigger($trigger->ID);
     //Not throwing an exception here constitutes successful completion.
 }
 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.');
 }
 /**
  * Send Footer contact us email
  *
  * @return boolean response
  */
 public function sendFooterContactUsEmail()
 {
     $postMarkKey = getenv("POSTMARK_API_KEY");
     if (empty($postMarkKey)) {
         return false;
     }
     $client = new PostmarkClient($postMarkKey);
     $input = Input::all();
     if (!empty($input['email']) && !empty($input['name']) && !empty($input['message'])) {
         try {
             $dateText = date('F j, Y, g:i a', strtotime('+5 hours 30 minutes')) . " IST";
             $sendResult = $client->sendEmail("<from-email>", "<to-email>", "Contact Us email sent on " . $dateText, "Name: " . $input['name'] . ", From: " . $input['email'] . ", Message: " . $input['message']);
             //Send an email thanking the visitor
             $sendResult = $client->sendEmail("<from-email>", $input['email'], "Thanks for contacting Income Tax Query!", "Thank You!");
         } catch (Exception $e) {
             echo 'Caught exception: ', $e->getMessage(), "\n";
             return false;
         }
     } else {
         return false;
     }
     return 'SEND';
 }
    $article = $_POST["article_id"];
    // update mySQL
    CS50::query("UPDATE portfolio SET status = 3 WHERE id = ?", $article);
    // set submission destination and subject
    $email_to = "*****@*****.**";
    $email_subject = "Crimson Article Submission";
    // Actual article text variable
    $articles = $_POST['articles'];
    // Start of email message
    $email_message = "Form details below.\n\n";
    // Get title of article
    $pieces = CS50::query("SELECT title FROM portfolio WHERE id = ?", $article);
    $piece = $pieces[0]["title"];
    // Get name of comper
    $compers = CS50::query("SELECT name, email FROM users WHERE userid = ?", $_SESSION["id"]);
    $name = $compers[0]["name"];
    $email = $compers[0]["email"];
    // Craft e-mail message body
    $email_message .= "Comper: " . $name . "\r\n";
    $email_message .= "Article Title: " . $piece . "\r\n";
    $email_message .= "Comments: " . $articles . "\r\n";
    $client = new PostmarkClient("211bda55-ecef-447c-ba35-7b2ca54e802f");
    // Send email
    $sendResult = $client->sendEmail("*****@*****.**", "*****@*****.**", "Comper Article Submissions", "{$email_message}");
    // Redirect
    redirect("/");
} else {
    if ($_SERVER["REQUEST_METHOD"] == "GET") {
        redirect("/");
    }
}
예제 #11
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!';
}
//}
예제 #12
0
 public function send($recipient, $subject, $message)
 {
     $client = new Postmark(self::KEY);
     $sendResult = $client->sendEmail(self::SENDER, $recipient, $subject, $message);
 }
예제 #13
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;
     }
 }
예제 #14
0
            $type = $user['type'];
            if ($type == "employer") {
                header("Location: index.php");
            }
        }
    }
} else {
}
include 'attachment.php';
require_once './vendor/autoload.php';
use Postmark\PostmarkClient;
use Postmark\Models\PostmarkException;
use Postmark\Models\PostmarkAttachment;
try {
    // Example request
    $client = new PostmarkClient("f5662a2d-8885-4cd1-b0b2-65b084216b3a");
    //$_FILES[file][name][type][size]
    $attachment = PostmarkAttachment::fromFile($target_dir . basename($_FILES["file"]["name"]), basename($_FILES["file"]["name"]), "text/plain");
    $sendResult = $client->sendEmail("*****@*****.**", $_POST['tosend'], "You Have a Request (No Reply)", "* You have a job application request from:" . "<br><br><br>" . "Name: " . $_POST['aname'] . "<br><br>" . "Age: " . $_POST['age'] . "<br><br>" . "Have Work Experience: " . $_POST['experience'] . "<br><br>" . "Experience About Previous Jobs: " . $_POST['area'] . "<br><br>" . "Contact: " . $_POST['contact'] . "<br><br>" . "Email: " . $_POST['email'] . "<br><br>" . "(Attachments is provided within the email)" . "<br><br>", "Attachement body", NULL, true, NULL, NULL, NULL, NULL, [$attachment]);
} catch (PostmarkException $ex) {
    // If client is able to communicate with the API in a timely fashion,
    // but the message data is invalid, or there's a server error,
    // a PostmarkException can be thrown.
    echo $ex->httpStatusCode;
    echo $ex->message;
    echo $ex->postmarkApiErrorCode;
} catch (Exception $generalException) {
    // A general exception is thown if the API
    // was unreachable or times out.
}
if ($sendResult) {
 function testClientCanSendMailWithTemplate()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $result = $client->createTemplate('test-php-template-' . date('c'), "{{subject}}", "Hello <b>{{name}}</b>!", "Hello {{name}}!");
     $emailResult = $client->sendEmailWithTemplate($tk->WRITE_TEST_SENDER_EMAIL_ADDRESS, $tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS, $result->templateid, array("subjectValue" => "Hello!"));
     $this->assertEquals(0, $emailResult->ErrorCode);
 }
예제 #16
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');
         }
     }
 }
 /**
  * Send email through Postmark's REST API
  *
  * @return bool (true = sent successfully)
  */
 private function sendPostmarkEmail($to, $from, $subject, $htmlContent = NULL, $attachedFiles = NULL, $customHeaders = NULL, $plainContent = NULL)
 {
     $apiKey = $this->config()->get('api_key');
     $senderSignatures = $this->config()->get('sender_signatures');
     $cc = NULL;
     $bcc = NULL;
     $replyTo = NULL;
     if (!$apiKey) {
         user_error('A Postmark App API key is required to send email', E_USER_ERROR);
     }
     if (!($htmlContent || $plainContent)) {
         user_error("Can't send email with no content", E_USER_ERROR);
     }
     if (empty($senderSignatures)) {
         user_error('At least one Postmark App sender signature is required to send email', E_USER_ERROR);
     }
     // Parse out problematic custom headers
     if (is_array($customHeaders)) {
         if (array_key_exists('Cc', $customHeaders)) {
             $cc = $customHeaders['Cc'];
             unset($customHeaders['Cc']);
         }
         if (array_key_exists('Bcc', $customHeaders)) {
             $bcc = $customHeaders['Bcc'];
             unset($customHeaders['Bcc']);
         }
         if (array_key_exists('Reply-To', $customHeaders)) {
             $replyTo = $customHeaders['Reply-To'];
             unset($customHeaders['Reply-To']);
         }
         if (empty($customHeaders)) {
             $customHeaders = NULL;
         }
     } else {
         $customHeaders = NULL;
     }
     // Ensure from address is valid
     if (!in_array($from, $senderSignatures)) {
         // Fallback to first valid signature
         if (!$replyTo) {
             $replyTo = $from;
         }
         $from = $senderSignatures[0];
     }
     // Set up attachments
     $attachments = array();
     if ($attachedFiles && is_array($attachedFiles)) {
         foreach ($attachedFiles as $f) {
             $attachments[] = PostmarkAttachment::fromRawData($f['contents'], $f['filename'], $f['mimetype']);
         }
     }
     // Send the email
     try {
         $client = new PostmarkClient($apiKey);
         $sendResult = $client->sendEmail($from, $to, $subject, $htmlContent, $plainContent, $tag = NULL, $trackOpens = true, $replyTo, $cc, $bcc, $customHeaders, $attachments);
         return true;
     } catch (PostmarkException $ex) {
         // If client is able to communicate with the API in a timely fashion,
         // but the message data is invalid, or there's a server error,
         // a PostmarkException can be thrown.
         user_error("Postmark Exception: {$ex->message} (Error code: {$ex->postmarkApiErrorCode})", E_USER_WARNING);
         return false;
     } catch (Exception $generalException) {
         // A general exception is thown if the API
         // was unreachable or times out.
         user_error('Postmark API was unreachable or timed out', E_USER_WARNING);
         return false;
     }
 }
 public function sendPostmarked($to, $from, $subject, $htmlContent, $plainContent, $attachedFiles, $customheaders, $signature = null)
 {
     if (empty($signature)) {
         $signature = PostmarkSignature::get()->filter('Email', $from)->first();
     }
     if (!$signature) {
         $signature = PostmarkSignature::get()->filter('IsDefault', 1)->first();
     }
     $client = new PostmarkClient(SiteConfig::current_site_config()->PostmarkToken);
     $customerIDs = PostmarkHelper::client_list()->filter('Email', explode(',', $to))->column('ID');
     $message = null;
     if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails) {
         $message = new PostmarkMessage(array('Subject' => $subject, 'Message' => $htmlContent, 'PlainMessage' => $plainContent, 'ToID' => implode(',', $customerIDs), 'FromID' => $signature ? $signature->ID : $signature, 'InReplyToID' => self::$reply_to_message));
         $message->write();
     }
     $cc = null;
     if (isset($customheaders['CC'])) {
         $cc = $customheaders['CC'];
         unset($customheaders['CC']);
     }
     if (isset($customheaders['cc'])) {
         $cc = $customheaders['cc'];
         unset($customheaders['cc']);
     }
     $bcc = null;
     if (isset($customheaders['Bcc'])) {
         $bcc = $customheaders['Bcc'];
         unset($customheaders['Bcc']);
     }
     if (isset($customheaders['BCC'])) {
         $bcc = $customheaders['bcc'];
         unset($customheaders['BCC']);
     }
     if (isset($customheaders['bcc'])) {
         $bcc = $customheaders['bcc'];
         unset($customheaders['bcc']);
     }
     $attachments = null;
     if ($attachedFiles && is_array($attachedFiles)) {
         $attachments = array();
         foreach ($attachedFiles as $attachment) {
             $attachments[] = PostmarkAttachment::fromRawData($attachment['contents'], $attachment['filename'], $attachment['mimetype']);
             if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails) {
                 $postmarkAttachment = new Attachment(array('Content' => base64_encode($attachment['contents']), 'FileName' => $attachment['filename'], 'ContentType' => $attachment['mimetype'], 'PostmarkMessageID' => $message->ID, 'Length' => strlen($attachment['contents'])));
                 $postmarkAttachment->write();
             }
         }
     }
     $arrangedHeaders = null;
     if ($customheaders && is_array($customheaders) && count($customheaders)) {
         $arrangedHeaders = array();
         foreach ($customheaders as $key => $val) {
             $arrangedHeaders[$key] = $val;
         }
     }
     $sendResult = $client->sendEmail($signature ? $signature->Email : $from, $to, $subject, $htmlContent, $plainContent, null, true, $message ? $message->replyToEmailAddress() : $from, $cc, $bcc, $arrangedHeaders, $attachments);
     if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails && $sendResult->__get('message') == 'OK') {
         $message->MessageID = $sendResult->__get('messageid');
         $message->write();
     }
     return $sendResult->__get('message') == 'OK';
 }
예제 #19
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);
    }