user3869231
user3869231

Reputation: 342

Twilio Error message that is not in documentation. "Message body is required"

My code is returning an error but i cant find the error in any of the docs or error codes.

The Services_Twilio_RestException is returning: "Message body is required." Which is not a documented error. What could be the case here?

The code successfully sends the SMS to the first recipient, and then all other recipients in the loop return the error "Message body is required".

Here is the full code.

foreach ($recipients as $recipient) {
    try {
        $message = $client->account->messages->create([
        "From" => $from,
        "To"   => '+1' . $recipient->phone_number,
        "Body" => stripslashes($message->afternoon_text),
    ]);
    } catch (Services_Twilio_RestException $e) {
        $db->query("INSERT INTO error_logs SET error='" . addslashes($e->getMessage()) . "'");
    }
}

Upvotes: 0

Views: 1300

Answers (1)

philnash
philnash

Reputation: 73055

Twilio developer evangelist here.

I would hope that the message would be somewhat self-documenting. It is indicating that in order to send an SMS message you need to include a message body.

From your code, I can see you are sending a body. However, can you guarantee that stripslashes($message->afternoon_text) is not empty? You don't show in your code where $message has come from, but my guess is that $message->afternoon_text is just returning an empty string. I'd look into that if I were you.

Upvotes: 1

Related Questions