Set $_SERVER variable when calling PHP from command line?
问题 Is it possible to pass a $_SERVER variable to a PHP script via the command line? Specifically I am trying to set the $_SERVER['recipient'] manually so I can test email piping without setting up a mail server. 回答1: On *nix: $ recipient="email@domain.com" php script.php <?php print_r($_SERVER); Test: $ recipient="email@domain.com" php script.php | grep recipient [recipient] => something@domain.com Or, you can export it or setenv (depending on your OS), like $ export recipient="email@domain.com"