PHP code example of priyolahiri / sendgrid-php

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

    

priyolahiri / sendgrid-php example snippets



$sendgrid = new SendGrid('username', 'password');

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       setFrom('[email protected]')->
       setSubject('Subject goes here')->
       setText('Hello World!')->
       setHtml('<strong>Hello World!</strong>');

$sendgrid->smtp->send($mail);

$sendgrid->web->send($mail);

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       ...
       addCategory("Category 1")->
       addCategory("Category 2");

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       ...
       addAttachment("../path/to/file.txt");    

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       addTo("[email protected]")->
       addTo("[email protected]")->
       ...
       setHtml("Hey %name%, we've seen that you've been gone for a while")->
       addSubstitution("%name%", array("John", "Harry", "Bob"));

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       addTo("[email protected]")->
       addTo("[email protected]")->
       ...
       setHtml("Hey %name%, you work at %place%")->
       addSubstitution("%name%", array("John", "Harry", "Bob"))->
       addSubstitution("%place%", array("%office%", "%office%", "%home%"))->
       addSection("%office%", "an office")->
       addSection("%home%", "your house");

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       ...
       addUniqueArgument("Customer", "Someone")->
       addUniqueArgument("location", "Somewhere");

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       ...
       addFilterSetting("gravatar", "enable", 1)->
       addFilterSetting("footer", "enable", 1)->
       addFilterSetting("footer", "text/plain", "Here is a plain text footer")->
       addFilterSetting("footer", "text/html", "<p style='color:red;'>Here is an HTML footer</p>");

$mail = new SendGrid\Mail();
$mail->addTo('[email protected]')->
       ...
       addHeader("category", "My New Category");

git clone [email protected]:sendgrid/sendgrid-php.git