发送电子邮件与多个消息给不同的用户在sendgrid

发送电子邮件与多个消息给不同的用户在sendgrid

问题描述:

我们正在使用sendgrid电子邮件,发送电子邮件与多个消息给不同的用户在sendgrid

,我们已经尽力了,

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

如何设置不同 - 不同$email->setHtml(array($message1,$message1))在同一时间。

+0

解释'不同 - 不同$消息在同一时间.'? – urfusion

+0

@fusion,编辑问题 – SagarPPanchal

+0

所以你想发送不同的消息给不同的用户?你应该为此使用不同的实例。 –

根据我的理解你的问题,你想发送不同的消息到不同的电子邮件ID。这可以通过

$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++; 
} 
+0

当'$ i == 2'时,这将在'$ message'上失败。 –

+0

@AlejandroIván:我只是创建一个理解方法的例子。 – urfusion

+0

赞赏:) +1 :) thanx很多,它为我工作 – SagarPPanchal

至于你的问题是混乱来实现,我会假设你想不同的电子邮件发送到列表中的所有用户。所以:

$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. 
}