Created
February 23, 2020 10:52
-
-
Save JAMEMSU/871b6e4a81b0ff30f14d961e6251146f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require 'vendor/autoload.php'; | |
| use SendGrid\Mail\Personalization; | |
| use SendGrid\Mail\To; | |
| // Declare a new SendGrid Mail object | |
| $email = new \SendGrid\Mail\Mail(); | |
| // Define the primary email | |
| $email->setFrom("[email protected]", "Your Name"); | |
| $email->setSubject("Group Email to Twilio Subscribers"); | |
| // Define the additional email addresses | |
| $email_addresses = [ | |
| "[email protected]","[email protected]", | |
| ]; | |
| foreach ( $email_addresses as $email_address ) { | |
| $personalization = new Personalization(); | |
| $personalization->addTo( new To( $email_address ) ); | |
| $email->addPersonalization( $personalization ); | |
| } | |
| $email->addContent("text/plain", "Sending bulk emails is easy with SendGrid"); | |
| $email->addContent("text/html", "Sending bulk emails is easy with SendGrid"); | |
| $sendgrid = new \SendGrid('API_KEY'); | |
| try { | |
| $response = $sendgrid->send($email); | |
| print $response->statusCode() . "\n"; | |
| print_r($response->headers()); | |
| print $response->body() . "\n"; | |
| echo "email sent!\n"; | |
| } catch (Exception $e) { | |
| echo 'Caught exception: '. $e->getMessage() ."\n"; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment