PHP code example of sprintcube / cakephp-sendgrid

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

    

sprintcube / cakephp-sendgrid example snippets


Plugin::load('SendGrid');

'EmailTransport' => [
...
  'sendgrid' => [
      'className' => 'SendGrid.SendGrid',
      'apiKey' => 'your-api-key' // your api key
  ]
]

'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    ],
    'sendgrid' => [
        'transport' => 'sendgrid'
    ]
]

$email = new SendGridMailer();
$email->setFrom(['[email protected]' => 'CakePHP SendGrid'])
    ->setTo('[email protected]')
    ->addTo('[email protected]')
    ->addCc('[email protected]')
    ->setSubject('Email from CakePHP SendGrid plugin')
    ->deliver('Message from CakePHP SendGrid plugin');

$email = new SendGridMailer();
$email->setFrom(['[email protected]' => 'CakePHP SendGrid'])
    ->setTo('[email protected]')
    ->setHeaders([
        'X-Custom' => 'headervalue',
        'X-MyHeader' => 'myvalue'
    ])
    ->setSubject('Email from CakePHP SendGrid plugin')
    ->deliver('Message from CakePHP SendGrid plugin');

$email = new SendGridMailer();
$email->setFrom(['[email protected]' => 'CakePHP SendGrid'])
    ->setTo('[email protected]')
    ->setSubject('Email from CakePHP SendGrid plugin')
    ->setAttachments([
        'cake_icon1.png' => Configure::read('App.imageBaseUrl') . 'cake.icon.png',
        'cake_icon2.png' => ['file' => Configure::read('App.imageBaseUrl') . 'cake.icon.png'],
        WWW_ROOT . 'favicon.ico'
    ])
    ->deliver('Message from CakePHP SendGrid plugin');

$email = new SendGridMailer();
$email->setTo('[email protected]')
    ->setTemplate('d-xxxxxx')
    ->deliver();

$email = new SendGridMailer();
$email->setTo('[email protected]')
    ->setSendAt(1649500630)
    ->deliver();