Skip to content

Instantly share code, notes, and snippets.

@wonjun27
Created March 5, 2015 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wonjun27/3dac2e74594f9096b13d to your computer and use it in GitHub Desktop.
Save wonjun27/3dac2e74594f9096b13d to your computer and use it in GitHub Desktop.
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");
$email
->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