PHP code example of oskargunther / sendgrid-bundle

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

    

oskargunther / sendgrid-bundle example snippets


class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            ....
            new OG\SendGridBundle\OGSendGridBundle(),
        ];

    }
}

use OG\SendGridBundle\Exception\SendGridException;

$provider = $this->get('og_send_grid.provider');

$email = $provider->createMessage();

$email->setFrom("[email protected]", "Example User");
$email->setSubject("Test subject");
$email->addTo("[email protected]", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent("text/html", "<strongand easy to do anywhere, even with PHP</strong");

try {
    $messageId = $provider->send($email);
} catch (SendGridException $e) {
    echo 'Caught exception: '. $e->getMessage() ."\n";
}

use OG\SendGridBundle\Event\WebHookEvent;
use OG\SendGridBundle\EventSubscriber\WebHookEventSubscriber;

class WebHookSubcriber extends WebHookEventSubscriber
{
    function onBounce(WebHookEvent $event)
    {
        $event->getWebHook()->getSmtpId();
    }

    function onClick(WebHookEvent $event)
    {
    }
    
    function onDeferred(WebHookEvent $event)
    {
    }

    function onDelivered(WebHookEvent $event)
    {
    }
    
    function onDropped(WebHookEvent $event)
    {
    }

    function onGroupResubscribe(WebHookEvent $event)
    {
    }

    function onGroupUnsubscribe(WebHookEvent $event)
    {
    }

    function onOpen(WebHookEvent $event)
    {
    }

    function onProcessed(WebHookEvent $event)
    {
    }

    function onSpamreport(WebHookEvent $event)
    {
    }

    function onUnsubscribe(WebHookEvent $event)
    {
    }

}