8

我想使用发送网格发送群组消息。我的群组有 100 名成员。当我发送群组消息时,发送了 50 到 80 条消息,然后显示一个空白页面:

NetworkError: 500 Internal Server Error

我的代码是,

set_time_limit (0);
$usernames = 'username'; // Must be changed to your username
$passwords = 'password';  // Must be changed to your password
// Create new swift connection and authenticate
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 25);
$transport ->setUsername($usernames);
$transport ->setPassword($passwords);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// add SMTPAPI header to the message
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $hdr->asJSON());
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
if ($recipients = $swift->send($message,$failures)){
    $message= 'Message sent';
}else{
    $message= "Something went wrong -  message not sent, please try later";
}

asJSON:

{
  "to": [
    ""
  ],
  "sub": {
    "-name-": [
      "anu"
    ],
    "-time-": [
      "12 PM"
    ]
  },
  "category": "initial",
  "filters": {
    "footer": {
      "settings": {
        "enable": 1,
        "text\/plain": "Thank you "
      }
    }
  }
}
4

2 回答 2

1

我建议你看看排队解决方案。检查github 中的slm/queue。对于长列表可能会导致服务器超过最大执行时间,使用队列服务将解决这个问题,所有消息将按顺序传递。

于 2014-10-16T08:30:46.963 回答
0

看起来to参数是问题:

"to": [
    ""
]

只需确保在输出中添加一封电子邮件,就可以了:

"to": [
    "some@email.com"
]

这个答案归功于上面的@Swift。

于 2014-03-27T05:40:04.537 回答