getenv('SENDGRID_API_KEY')在某些条件下失败

I am calling getenv('SENDGRID_API_KEY') from contact.php file which is called from contact.html that describes the details of a standard contact form.

Everything goes fine but the command:

$sendgrid_apikey = getenv('SENDGRID_API_KEY');

fails causing the error:

{"errors":["Permission denied, wrong credentials"],"message":"error"}

The error shows after submitting the contact form with all required fields filled.

I can get it to work from a simple .php script such as:

<?php
     $sendgrid_apikey = getenv('SENDGRID_API_KEY');
     echo "apikey: $sendgrid_apikey  
"
?>

The above script echo's the SENDGRID_API_KEY, no problem at all. The issue happens when I call it in a contact.php that in turn is called from contact.html with the following form definition:

<form action="contact.php" method="post">

Here is how SENDGRID_API_KEY is defined:

export SENDGRID_API_KEY = "abcdefgh"
source ~/.bashrc

If I invoke:

echo $SENDGRID_API_KEY

In the terminal, I get:

abcdefgh

Any idea where is this coming from?

Thanks