SagarPPanchal
SagarPPanchal

Reputation: 10121

Send email with multiple messages to different users in sendgrid

We are using sendgrid for email,

we have tried,

$email = new SendGrid\Email();
$emails = array("[email protected]", "[email protected]", "[email protected]");
$email->setTos($emails);
$email->setHtml(array($message1,$message1));
$sendgrid->send($email);

How to set different - different $email->setHtml(array($message1,$message1)) at a time.

Upvotes: 2

Views: 228

Answers (2)

Alejandro Iván
Alejandro Iván

Reputation: 4061

As your question is confusing, I will assume you want to send different email messages to all users in the list. So:

$email = new SendGrid\Email();
$emails = array("[email protected]", "[email protected]", "[email protected]");
$messages = array("message1", "message2");

foreach ($messages as $msg) { // Grab every message...
    $email->setTos($emails); // for everyone...
    $email->setHtml($msg); // set it as the body...
    $sendgrid->send($email); // and send it.
}

Upvotes: 1

urfusion
urfusion

Reputation: 5501

As per I understand from your question you want to send different messages to different email ids. Which can be achieve by

$email = new SendGrid\Email();
$emails = array("[email protected]", "[email protected]", "[email protected]");
$message = array("message1","message2","message3"); //create a array of messages according to email ids 
$i =0 ;
foreach ($emails as $value) {
    $email->setTos($value);
    $email->setHtml($message[$i]);
    $sendgrid->send($email);
    $i++;
}

Upvotes: 2

Related Questions