8

I want to send group messages using send grid. My group have 100 members.When I send a group message, 50 to 80 messages are delivered and then it shows a blank page as:

NetworkError: 500 Internal Server Error

My Code is,

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 "
      }
    }
  }
}
Abdul Manan
  • 2,255
  • 3
  • 27
  • 51
Navaneetha Nair
  • 312
  • 2
  • 12
  • Could you give us the output of `asJSON`? It would help with debugging. – Swift Dec 10 '12 at 18:14
  • @Swift output of asJSON is {"to": [""], "sub": {"-name-": ["anu"], "-time-": ["12 PM"]}, "category": "initial", "filters": {"footer": {"settings": {"enable":1,"text\/plain": "Thank you "}}}} – Navaneetha Nair Dec 11 '12 at 06:59
  • 4
    Looks like to `to` parameter is the issue. Doesn't look like `$to` is set in your code. – Swift Dec 11 '12 at 17:54
  • Also, beware the limitations pr day. http://sendgrid.com/docs/User_Guide/sending_practices.html – Vidar Vestnes Jan 28 '14 at 13:55
  • 2
    Check if you are not out of some resources like memory limit, max execution time limit, CPU usage limit, or other. You should find that information in php log file, so turn on error loging if it is not. It is also good idea to have a look at http server log file. – Robert Trzebiński Feb 15 '14 at 17:28
  • Have you looked at what Robert asked? Check your php errors.log. Please provide some response - this is 4 months old. – MikeMurko Mar 23 '14 at 15:08

2 Answers2

1

I suggest you look into queeing solution . Check slm/queue in github for that. For long lists it may cause the server to exceed the maximum execution time, Using queue services will solve that, and all messages will be delivered in sequence.

0

Looks like the to parameter is the issue:

"to": [
    ""
]

Just make sure that you add an email to the output and you should be good:

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

Credit to @Swift above for this answer.

seangates
  • 1,467
  • 11
  • 28