【问题标题】:Sending group messages using send grid, gives 500 Internal Server Error使用发送网格发送组消息,给出 500 内部服务器错误
【发布时间】:2012-11-26 09:04:01
【问题描述】:

我想使用发送网格发送群组消息。 我的群组有 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 "
      }
    }
  }
}

【问题讨论】:

  • 你能给我们asJSON的输出吗?这将有助于调试。
  • @Swift 的 asJSON 输出是 {"to": [""], "sub": {"-name-": ["anu"], "-time-": ["12 PM"]}, "category": "initial", "filters": {"footer": {"settings": {"enable":1,"text\/plain": "谢谢"}}}}
  • 看起来to 参数是问题所在。看起来您的代码中没有设置 $to
  • 另外,请注意公关日的限制。 sendgrid.com/docs/User_Guide/sending_practices.html
  • 检查您是否没有超出某些资源,例如内存限制、最大执行时间限制、CPU 使用限制或其他。您应该在 php 日志文件中找到该信息,如果没有,请打开错误日志记录。查看 http 服务器日志文件也是一个好主意。

标签: codeigniter email swiftmailer


【解决方案1】:

看起来to 参数是问题所在:

"to": [
    ""
]

只要确保你在输出中添加了一封电子邮件,你就应该很好:

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

感谢以上@Swift 的回答。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2019-02-12
      • 2023-03-20
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 2022-11-01
      相关资源
      最近更新 更多