PHP code example of aslamhus / sendgrid-email-wrapper

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

    

aslamhus / sendgrid-email-wrapper example snippets


   composer 

   // add your api key
   $email = new Email('your-sendgrid-api-key');
   // make sure to add your single sender identity email and name
   $didSend = $email->sendVerifyIntegrationEmail(['[email protected]', 'Verified User']);
   // $didSend will return true if everything is set up correctly.
   


$email = new Email('your-sendgrid-api-key')
    ->setFrom('[email protected]', 'Sender Name')
    ->addTo('[email protected]', 'Recipient Name')
    ->setSubject('Test email')
    ->addContent('text/plain', 'Hello world!')
    ->send();


$email = new Email('your-sendgrid-api-key')
    ->setFrom('[email protected]', 'Sender Name')
    ->addTo('[email protected]', 'Recipient Name')
    ->setSubject('Test email')
    ->setTemplateId('your-template-id')
    ->addDynamicTemplateDatas([
        'subject' => 'My dynamic template email'
        'name' => '2020-01-01',
        'link' => 'https://www.example.com',
    ])
    ->send();

  $email->addAttachment('path/to/file.pdf', 'application/pdf', 'document.pdf');
  

  $email->addContent('text/plain', 'This is the plain text content');
  $email->addContent('text/html', '<p>This is the HTML content</p>');
  

  // retrieve the response body, headers and status code after sending
  $response = $email->getResponse();
  print_r($response->headers());
  echo $response->statusCode()
  echo $response->body()

  

composer run test