Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending group messages using send grid, gives 500 Internal Server Error

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 "
      }
    }
  }
}
like image 413
Navaneetha Nair Avatar asked Dec 08 '12 08:12

Navaneetha Nair


People also ask

How do I fix a 500 Internal server error?

Clear your browser cache and cookies Check these articles on deleting the cache on an Android phone or iPhone, if you use a mobile device. Alternatively, you can test opening the page from another browser. For instance, if you use Chrome, try Firefox or vice versa.

Why is SendGrid not sending?

To fix this issue, you'll want to make sure that you've configured your setup to connect to smtp.sendgrid.net using authentication, and that the credentials you're using are your SendGrid username and a properly configured API key as the password. For more on API keys, see API Keys.

What does 500 internal server error mean?

The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.


1 Answers

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.

like image 193
jerryManyanda Avatar answered Dec 21 '22 23:12

jerryManyanda