title: SendGrid API 405 Method Not Allowed when trying to send an email
body: <p>EDIT 3: This 405 error has something to do with my IIS Express dev environment. I managed to get everything working on my azure web app.</p>
  
  <p>EDIT 2: Duh. I didnt have the environment variable set.</p>
  
  <p>EDIT: I have made some progress thanks to you helpful fellows. Seems I have an authentication problem now even though I am using a fresh API key from SendGrid. I am current getting this error:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>401 Array ( [0] =&gt; HTTP/1.1 401 Unauthorized [1] =&gt; Server: nginx [2] =&gt; Date: Sun, 17 Nov 2019 20:50:16 GMT [3] =&gt; Content-Type: application/json [4] =&gt; Content-Length: 88 [5] =&gt; Connection: keep-alive [6] =&gt; Access-Control-Allow-Origin: https://sendgrid.api-docs.io [7] =&gt; Access-Control-Allow-Methods: POST [8] =&gt; Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl [9] =&gt; Access-Control-Max-Age: 600 [10] =&gt; X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html [11] =&gt; [12] =&gt; ) {"errors":[{"message":"Permission denied, wrong credentials","field":null,"help":null}]}</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have a simple button to call a test php file and am working on getting SendGrid for my website.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form method="post" action="php/send_form_email.php"&gt;
                      &lt;input type="submit" value="click on me!"&gt;
                  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Then here is the send_form_email.php file:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
          // You need to install the sendgrid client library so run:     
          // composer require sendgrid/sendgrid
          try
       {
        require 'D:/home/site/wwwroot/vendor/autoload.php';
       }
       catch (Exception $e) {
        echo 'exception' . '&lt;br&gt;';
        var_dump($e);
       }
       
       $email = new \SendGrid\Mail\Mail();
  $email-&gt;setFrom("test@example.com", "Example User");
  $email-&gt;setSubject("Sending with SendGrid is Fun");
  $email-&gt;addTo("test@example.com", "Example User");
  $email-&gt;addContent(
      "text/plain", "and easy to do anywhere, even with PHP"
  );
  $email-&gt;addContent(
      "text/html", "&lt;strong&gt;and easy to do anywhere, even with PHP&lt;/strong&gt;"
  );
  $sendgrid = new \SendGrid(getenv('API_KEY_HERE'));
  try {
      $response = $sendgrid-&gt;send($email);
      print $response-&gt;statusCode() . "\n";
      print_r($response-&gt;headers());
      print $response-&gt;body() . "\n";
  } catch (Exception $e) {
      echo 'Caught exception: ',  $e-&gt;getMessage(), "\n";
  }
      ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I installed any composer/sendgrid/curl that I have come across successfully on both my machine and my azure web app.</p>
  
  <p>Any help is appreciated. Thanks.</p>