我试图在我的php中解析主机名网址以获取电子邮件,但我没有获取网址主机名。请参阅下面的代码。我不知道我在这里做错了什么。的 {$基本URL}
// hostname variable
$baseURL = $SERVER['SERVERNAME'];
$message_contents = "Greetings ".trim($fullName).".\n\nPlease follow the link below to reset your password.\n\n{$baseURL}/ssp/resetssp.php?token=".$token."\n\n(*Please do not reply to this email.)\n\nIf you did not request that your password be changed.\n\nThank you,";
以下是我在没有主机名解析的情况下收到的电子邮件。
/ssp/resetssp.php?token=WF5IMKKT7AZCV5V19CRKSWWCA7PM7PCE
我想得到这样的输出:
https://domainname/ssp/resetssp.php?token=WF5IMKKT7AZCV5V19CRKSWWCA7PM7PCE
答案 0 :(得分:0)
您可以使用$_SERVER['SERVER_NAME']
或$_SERVER['HTTP_HOST']
取决于您的需求。本文解释了它们之间的区别:SERVER_NAME Versus HTTP_HOST。因此,请尝试使用此代码:
// hostname variable
$baseURL = $_SERVER['SERVER_NAME'];
$message_contents = "Greetings ".trim($fullName).".\n\nPlease follow the link below to reset your password.\n\n{$baseURL}/ssp/resetssp.php?token=".$token."\n\n(*Please do not reply to this email.)\n\nIf you did not request that your password be changed.\n\nThank you,";