Inheritance: extends ResourceBase
<?php

/*Cron will automaticly run this program every minute, seeing which polls are old. Old polls have their data sent to the specified email and are removed.*/
namespace Examples\Transmisson;

require_once "config.php";
require 'vendor/autoload.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
SparkPost::setConfig(["key" => SPARK_KEY]);
$result = $db->query("SELECT * FROM poll WHERE end_time < NOW()");
while ($row = $result->fetch_array()) {
    try {
        $results = Transmission::send(array("from" => "From Envelope <*****@*****.**>", "recipients" => array(array("address" => array("email" => $row['email']))), "template" => "suggest-app-poll-dat", 'substitutionData' => $row));
    } catch (\Exception $exception) {
        echo $exception->getMessage();
    }
}
$db->query("DELETE FROM poll WHERE end_time < NOW()");
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::all();
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::send(array("campaign" => "my-campaign", "metadata" => array("sample_campaign" => true, "type" => "these are custom fields"), "substitutionData" => array("name" => "Test Name"), "description" => "my description", "replyTo" => "*****@*****.**", "customHeaders" => array("X-Custom-Header" => "Sample Custom Header"), "trackOpens" => false, "trackClicks" => false, "from" => "From Envelope <*****@*****.**>", "html" => "<p>Hello World! Your name is: {{name}}</p>", "text" => "Hello World!", "subject" => "Example Email: {{name}}", "recipients" => array(array("address" => array("email" => "*****@*****.**")))));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::send(array('recipients' => array(array('address' => array('email' => '*****@*****.**'))), 'rfc822' => "Content-Type: text/plain\nFrom: From Envelope <*****@*****.**>\nSubject: Example Email\n\nHello World"));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::send(array("campaign" => "my-campaign", "from" => "From Envelope <*****@*****.**>", "html" => "<p>Hello World! Your name is: {{name}}</p>", "text" => "Hello World!", "subject" => "Example Email: {{name}}", "recipientList" => 'Example List'));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
 /**
  * @desc tests bad response
  * @expectedException Exception
  * @expectedExceptionMessageRegExp /Unable to contact Transmissions API:.* /
  */
 public function testSendForCatchAllException()
 {
     $mock = new MockPlugin();
     $mock->addResponse(new Response(500));
     $this->client->addSubscriber($mock);
     Transmission::send(array('text' => 'awesome email'));
 }
<?php

namespace Examples\Transmisson;

require_once "../config.php";
require '../vendor/autoload.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
SparkPost::setConfig(["key" => SPARK_KEY]);
try {
    $results = Transmission::send(array("from" => "From Envelope <*****@*****.**>", "recipients" => array(array("address" => array("email" => "*****@*****.**"))), "template" => "suggest-app-poll-dat", 'substitutionData' => array('question' => 'Who is awesome?', 'opt_1' => 'Brent', 'opt_2' => 'Brent of corse!', 'vote_1' => '69', 'vote_2' => '72')));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::send(array("from" => "From Envelope <*****@*****.**>", "recipients" => array(array("address" => array("email" => "*****@*****.**"))), "template" => "my-template"));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::send(array("from" => "From Envelope <*****@*****.**>", "html" => "<p>Hello World!</p>", "text" => "Hello World!", "subject" => "Example Email", "recipients" => array(array("address" => array("email" => "*****@*****.**")))));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::find('Your Transmission Id');
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}