post post_method导致找不到类?

时间:2015-10-18 02:51:37

标签: php http post composer-php

我遇到的问题是发出POST请求时,找不到任何外部类。问题仅存在于POST请求中。我做了一个完全正常的GET请求示例(可以使用SendGrid)所以我知道它不是composer autoloader的问题。 POST请求如何导致Fatal error: Class 'SendGrid' not found

<?php
$sendgrid = new SendGrid(REDACTED);
$email = new SendGrid\Email();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  var_dump($_POST);
    if(isset($_POST['name'])){ $name = $_POST['name']; }
    if(isset($_POST['email'])){ $from = $_POST['email']; }
    if(isset($_POST['message'])){ $message = $_POST['message']; }
    if(isset($_POST['g-recaptcha-response'])){ $captcha = $_POST['g-recaptcha-response']; }
    $secret = REDACTED;
    $recaptcha = new ReCaptcha\ReCaptcha($secret);

    $resp = $recaptcha->verify($captcha, $_SERVER['REMOTE_ADDR']);
    if ($resp->isSuccess()) {
      $email
          ->addTo('bar@example.com')
          ->setFrom($from)
          ->setSubject('New Contact')
          ->setText($message);

          $sendgrid->send($email);

    } else {
        $errors = $resp->getErrorCodes();
    }
}
elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
  $name = 'Jim';
  $from = 'foo@example.com';
  $message = 'test message';
    $email
        ->addTo('bar@example.com')
        ->setFrom($from)
        ->setSubject('New Contact: ' . $name)
        ->setText($message);

        $sendgrid->send($email);
}
?>

0 个答案:

没有答案