PHP code example of apostle / apostle-php

1. Go to this page and download the library: Download apostle/apostle-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

apostle / apostle-php example snippets


Apostle::setup("your-domain-key");

use Apostle\Mail;

$mail = new Mail(
	"template-slug",
	array("email" => "[email protected]", "name" => "Mal Curtis")
);

$mail->deliver();

$mail = new Mail("template-slug");
$mail->email = "[email protected]";
$mail->name = "Mal Curtis";
$mail->from = "[email protected]";
$mail->replyTo = "[email protected]";
$mail->website = "apostle.io"; // You can add any data your template needs

$mail->deliver();

$mail = new Mail("template-slug");
$mail->addAttachment("test.txt", "Some test text");
$mail->deliver();

$mail = new Apostle\Mail("template-slug");

echo $mail->deliver($failure);
// false

echo $failure;
// No email provided


use Apostle\Mail;
use Apostle\Queue;

$queue = new Queue();

for($i=0;$i<5;$i++){
	$mail = new Mail("template-slug");
	$mail->email = "user" . $i . "@example.org";
	$queue->add($mail);
}

$queue->deliver();


use Apostle\Mail;
use Apostle\Queue;

$queue = new Queue();

$mail = new Mail("template-slug");
$queue->add($mail);


$mail = new Mail(null, ["email" => "[email protected]"]);
$queue->add($mail);


echo $queue->deliver($failures);
// false

echo count($failures);
// 2

echo $failures[0]->deliveryError();
// "No email provided"

echo $failures[1]->deliveryError();
// "No template provided"