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.
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??