php notice undefined index http_host in $GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST']

五迷三道 提交于 2020-01-04 05:40:10

问题


Suddenly, I'm getting this notice from php after a recent php version update. It is used in several places (particularly my htmlMimeMail class).

Code is: $mail->setSMTPParams('*mail.xxxx.xxx*', 26, $GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST'], 1, '*email-name*', '*email-password*');

The notice is: Undefined index: HTTP_HOST in xxxx on line xxx

The codes seems to be working fine, but the notice is annoying and I expect notices are used for a reason. How can I clear this notice?


回答1:


$HTTP_SERVER_VARS is deprecated; use $_SERVER:

$mail->setSMTPParams('*mail.xxxx.xxx*', 26, $_SERVER['HTTP_HOST'], 1,
    '*email-name*', '*email-password*');


来源:https://stackoverflow.com/questions/11363070/php-notice-undefined-index-http-host-in-globalshttp-server-varshttp-host

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!