Masseleria
Masseleria

Reputation: 299

preserve recipients in the sendgrid API

I'm sending an email to multiple recipients using the sendgrid API !

<?php


$email = new SendGrid\Email();
$sendgrid = new SendGrid('API_KEY');

$email
    ->addTo(array('[email protected]','[email protected]'..))
    ->setFrom('[email protected]')
    ->setSubject('Subject goes here')
    ->setText('Hello World!')
    ->setHtml('<strong>Hello World!</strong>')
;

$sendgrid->send($email);

Now, I wanna know if there is any way to hide the second email in the "To" header for the first email?

Upvotes: 3

Views: 501

Answers (1)

bwest
bwest

Reputation: 9844

Use the SMTP API for mail-merge type functionality.

Using sendgrid-php, that looks like:

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo('[email protected]')
    ->addSmtpapiTo('[email protected]', 'Mike Bar')
;
$sendgrid->send($email);

Or for an array:

$email = new SendGrid\Email();
$emails = array("[email protected]", "Brian Bar <[email protected]>", "[email protected]");
$email->setSmtpapiTos($emails);
$sendgrid->send($email);

Upvotes: 3

Related Questions