Created
March 5, 2015 16:23
-
-
Save wonjun27/3dac2e74594f9096b13d to your computer and use it in GitHub Desktop.
This file contains 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
https://github.com/sendgrid/sendgrid-php | |
### Sending to 1,000s of emails in one batch | |
Sometimes you might want to send 1,000s of emails in one request. You can do that. It is recommended you break each batch up in 1,000 increments. So if you need to send to 5,000 emails, then you'd break this into a loop of 1,000 emails at a time. | |
```php | |
$sendgrid = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD); | |
$email = new SendGrid\Email(); | |
$recipients = array( | |
"alpha@mailinator.com", | |
"beta@mailinator.com", | |
"zeta@mailinator.com" | |
); | |
$names = array("Alpha", "Beta", "Zeta"); | |
->setFrom("from@mailinator.com") | |
->setSubject('[sendgrid-php-batch-email]') | |
->setTos($recipients) | |
->addSubstitution("%name%", $names) | |
->setText("Hey %name, we have an email for you") | |
->setHtml("<h1>Hey %name%, we have an email for you</h1>") | |
; | |
$result = $sendgrid->send($email); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment