Sendgrid-php: How to send bulk email to user

Created on 20 Aug 2018  路  4Comments  路  Source: sendgrid/sendgrid-php

require 'sendgrid-php/sendgrid-php.php';
$email_subject = 'Test email subject';
$email_body = '<p><strong>Hi </strong></p><p>This is a test email.</p>';
$email = new \SendGrid\Mail\Mail(); 
$email->setFrom("[email protected]", "example");
$email->setSubject($email_subject);
$email->addTo('[email protected]');
$email->addContent(
  "text/html", $email_body
);
$api_key = 'XXX-XXXX-XXX';
$sendgrid = new \SendGrid($api_key);
try {
  $response = $sendgrid->send($email);
  print $response->statusCode() . "\n";
  print_r($response->headers());
  print $response->body() . "\n";
} catch (Exception $e) {
  echo 'Caught exception: '. $e->getMessage() ."\n";
}

This code is working fine but when I am removing "to" field and entering all email id into "bcc", I am receiving an error saying that "to" field is mandatory. I want to send bulk email to everyone in bcc so that they can't see the email id of other members.

Please help how to do it.

unknown or a waiting for feedback question

All 4 comments

Hello @iamanupammaity,

I believe this is the example you need. Please let me know if you have any further questions.

With Best Regards,

Elmer

Thanks, it's worked.

The code is elegant.

One more question. What is the number of recipients I can send the email in a loop??

Hi @iamanupammaity,

1000 (source).

With Best Regards,

Elmer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

buddyy93 picture buddyy93  路  5Comments

izhukovich picture izhukovich  路  4Comments

micahwalter picture micahwalter  路  3Comments

bjornmann picture bjornmann  路  3Comments

morazain picture morazain  路  3Comments