我尝试创建一个可以从请求中记录HTTP信息然后通过电子邮件发送此信息的PHP。我正在尝试发送IP,URL引荐来源和网址请求)
这个想法是$emailContent
可以发送:
"Someone visited your webpage. IP address:".$remoteIpAddress;
"The referrer URL from the request was:".$urlRefer
"The URL input was: php?".$infoFromUrl
$ infoFromUrl意味着发送像log.php这样的网址信息?发送此信息通过邮件发送
任何人都可以帮助我:
<?php
$yourEmailAddress = "user@domain.com";
$emailSubject = "New Visitor on Webpage";
$remoteIpAddress = $_SERVER['REMOTE_ADDR'];
$emailContent = "Someone visited your webpage. IP address:".$remoteIpAddress;
// send the message
mail($yourEmailAddress, $emailSubject, $emailContent);
?>
答案 0 :(得分:-1)
您拥有的电子邮件代码非常基本,但应该可以使用 - 如果您想要更彻底的工作,请考虑PHPMailer。
记录非常简单:
$msg = "Someone visited your webpage. IP address:" . $remoteIpAddress.
"The referrer URL from the request was:" . $urlRefer .
"The URL input was: php?" . $infoFromUrl;
file_put_contents('log.txt', date('Y-m-d H:i:s ').$msg, FILE_APPEND | LOCK_EX);
或者您可以通过使用实现the PSR-3 standard的类来使其更复杂。