PHP code example of a2design-company / sendgrid-webapi-cakephp-plugin
1. Go to this page and download the library: Download a2design-company/sendgrid-webapi-cakephp-plugin 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/ */
a2design-company / sendgrid-webapi-cakephp-plugin example snippets
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('sendGrid');
$email->to('[email protected]');
$email->subject('Test email via SendGrid');
$email->send('Message');
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('sendGrid');
$email->template('default', 'default');
$email->emailFormat('html');
$email->viewVars(array('name' => 'Your Name'));
$email->to(array('[email protected]' => 'Recipient1', '[email protected]' => 'Recipient2'));
$email->subject('Test email via SendGrid');
$email->addHeaders(array('X-Tag' => 'my tag'));
$email->attachments(array(
'cake.icon.png' => array(
'file' => WWW_ROOT . 'img' . DS . 'cake.icon.png'
)
));
$email->send();
CakePlugin::load('Sendgrid');
class EmailConfig {
public $sendGrid = array(
'transport' => 'Sendgrid.Sendgrid',
'from' => '[email protected]',
'fromName' => 'You name',
'timeout' => 30,
'username' => '[email protected]', //SendGrid username
'password' => 'password', //SendGrid password
'client' => null,
'log' => false,
'emailFormat' => 'both',
'category' => 'transaction', //default SendGrid category for emails
'count' => 200, //count of email to send in one API call, max 500, default 500
);
}