PHP code example of vulcandigital / silverstripe-sendgrid

1. Go to this page and download the library: Download vulcandigital/silverstripe-sendgrid 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/ */

    

vulcandigital / silverstripe-sendgrid example snippets


$sendGrid = \Vulcan\SendGrid\SendGrid::create();
$sendGrid->setSubject("We have a sale for you!");
$sendGrid->setFrom('[email protected]');
$sendGrid->setFromName('My Site');
$sendGrid->setReplyTo('[email protected]');
$sendGrid->addRecipient('[email protected]', 'Reece Alexander', [
    ':salutation' => 'Mr',
    ':button_link' => 'https://example.com/store/offer?id=aASdGdjnklashewjk12321hjkasd213'
]);
$sendGrid->setBody("<p>We thought you'd like this awesome t-shirt!</p>");
$sendGrid->setTemplateId('your-template-id');
$sendGrid->addAttachment(Image::get()->first());
$sendGrid->send();

$sendGrid->addRecipient('[email protected]', 'John Doe', [
    ':salutation' => 'Mr',
    ':first_name' => 'John',
    ':last_name' => 'Doe'
]);
$sendGrid->addRecipient('[email protected]', 'Jane Doe', [
    ':salutation' => 'Mrs',
    ':first_name' => 'Jane',
    ':last_name' => 'Doe'
]);

$sendGrid->addCustomArg(':year', DBDatetime::now()->Year());

$file = Image::get()->first();
$sendGrid->addAttachment($file, $filename = null, $forcePublish = false); 

$sendgrid->addAttachment('/public_html/path/to/image.png'));
$sendgrid->addAttachment(Controller::join_links(Director::baseFolder(), '/path/to/image2.png'));

$sendGrid->setScheduleTo(DBDatetime::now()->getTimestamp() + 3600); // Schedule to send in 1 hour

$sendGrid->setSandboxMode(true);