【问题标题】:Send email with multiple messages to different users in sendgrid在 sendgrid 中向不同用户发送包含多条消息的电子邮件
【发布时间】:2016-04-21 13:14:38
【问题描述】:

我们正在使用 sendgrid 发送电子邮件,

我们已经尝试过了,

$email = new SendGrid\Email();
$emails = array("foo@bar.com", "another@another.com", "other@other.com");
$email->setTos($emails);
$email->setHtml(array($message1,$message1));
$sendgrid->send($email);

如何一次设置不同的 - 不同的$email->setHtml(array($message1,$message1))

【问题讨论】:

  • 解释different - different $message at a time.?
  • @urfusion,已编辑问题
  • 所以你想给不同的用户发送不同的消息?您应该为此使用不同的实例。
  • 据我所知,您希望向不同的电子邮件 ID 发送不同的消息。因此,您可以通过创建一个电子邮件 ID 和消息循环并每次调用发送函数来做到这一点

标签: php email sendgrid


【解决方案1】:

据我了解,您希望向不同的电子邮件 ID 发送不同的消息。可以通过以下方式实现

$email = new SendGrid\Email();
$emails = array("foo@bar.com", "another@another.com", "other@other.com");
$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++;
}

【讨论】:

  • $i == 2 时,这将在$message 上失败。
  • @AlejandroIván:我只是创建一个示例来理解这种方法。
  • @SagarPanchal:不客气。很高兴知道它有效。
  • @urfusion,第一个收件人收到所有邮件
  • @SagarPanchal :我只是代码(仅带有电子邮件 ID 的循环)并为我工作。我得到的循环输出是foo@bar.com message1 another@another.com message2 other@other.com message3。让我试试sendgrid
【解决方案2】:

由于您的问题令人困惑,我假设您想向列表中的所有用户发送不同的电子邮件。所以:

$email = new SendGrid\Email();
$emails = array("foo@bar.com", "another@another.com", "other@other.com");
$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.
}

【讨论】:

    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 2018-09-13
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    相关资源
    最近更新 更多