Search code examples
phpibm-cloudform-submitsendgridhttp-status-code-500

Submit button not working anymore on my Bluemix app (Error 500)


My app was working fine for about a entire month, but then, after 03/17 (last week) I keep getting this error message after I click on the submit button (my app sends an email with the details on the form using SendGrid). Error message on chrome after I click on Submit button:

myapp.mybluemix.net is currently unable to handle this request.
HTTP ERROR 500

The thing is that I don't remember changing anything substantial (I even tried older versions of my app and still didn't worked), but it looks like it's a Bluemix issue because it works fine on local.

Here is my log with the "cf log" command:

2017-03-20T19:24:55.65-0300 [APP/0]      OUT 22:24:55 httpd   | 169.54.180.77 -
- [20/Mar/2017:22:24:55 +0000] "POST /index.php HTTP/1.1" 500 - vcap_request_id=
682b55c0-a427-4984-78e5-3d192c613352 peer_addr=169.54.180.77
2017-03-20T19:24:55.65-0300 [APP/0]      OUT 22:24:55 httpd   | [Mon Mar 20 22:2
4:55.598001 2017] [proxy_fcgi:error] [pid 47:tid 140581812508416] [client 169.54
.180.77:48798] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error
: Call to undefined function SendGrid\\mb_convert_encoding() in /home/vcap/app/l
ib/vendor/sendgrid/sendgrid/lib/helpers/mail/Mail.php:744\nStack trace:\n#0 /hom
e/vcap/app/htdocs/index.php(129): SendGrid\\Content->__construct('text/plain', '
%PROPERTY={{Req...')\n#1 {main}\n  thrown in /home/vcap/app/lib/vendor/sendgrid/
sendgrid/lib/helpers/mail/Mail.php on line 744\n', referer: http://myapp.
mybluemix.net/index.php

I'm not sure how to interpret this error, please help!

here's a piece of my code:

// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
    $message = $sdrmsg;
require 'vendor/autoload.php';
// If you are not using Composer
// require("path/to/sendgrid-php/sendgrid-php.php");
$from = new SendGrid\Email("", "$email");
$subject = "REQUEST";
$to = new SendGrid\Email("email", "email@example.com");
$content = new SendGrid\Content("text/plain", $message);
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = 'mykey';
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo $response->body();
}

Solution

  • Error is- PHP message: PHP Fatal error: Uncaught Error: Call to undefined function SendGrid\mb_convert_encoding()

    Resolution: You will have to enable mb_string in your server. Are you using php_buildpack?

    mbstring is a supported extension of the php buildpack, but must be enabled explicitly.

    You may follow this answer to resolve your error https://developer.ibm.com/answers/questions/179545/how-to-enable-mbstring-extension-in-php-buildpack.html