将当前 URL 插入 PHP 电子邮件



我有一个视频网站,我需要创建一个链接或按钮,以便访问者可以单击以报告断开的链接。

我试图包括REQUEST_URI但到目前为止没有成功。网址永远不会显示。 以下是报告的内容.php:

<?php
$to = 'admin@domain';
$subject = 'domain.com Broken Link';
$message = '
<html>
<head>
<title>Dead Link from domain.com</title>
</head>
<body>
<p>The website contains a DEAD LINK</p>
<p>Please fix or remove the faulty file or page.</p>
<?php 
function url_origin( $s, $use_forwarded_host = false )
{
$ssl      = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
$sp       = strtolower( $s['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
$port     = $s['SERVER_PORT'];
$port     = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
$host     = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
$host     = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
return $protocol . '://' . $host;
}
function full_url( $s, $use_forwarded_host = false )
{
return url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI'];
}
$absolute_url = full_url( $_SERVER );
echo $absolute_url;
?>
</body>
</html>';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
mail($to, $subject, $message, implode("rn", $headers));
echo ("The report has been sent.<br>Thank you for your time.");
?>

你做错了。假设您当前处于http://example.com/some-page中,并且希望将此页面报告为断开的链接。然后在页面中放置一个"报告">按钮,如下所示:

<a href="report.php?url=<?= urlencode($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>">Report</a>

报告.php:

<?php
if (isset($_GET['url']) && filter_var($_GET['url'], FILTER_VALIDATE_URL)) {
$to = 'admin@example.com';
$subject = 'example.com Broken Link';
$message = 'The website contains a DEAD LINK.<br>Please fix or remove the faulty file or page: ' . urldecode($_GET['url']);
$headers = ['MIME-Version: 1.0', 'Content-type: text/html; charset=iso-8859-1'];
mail($to, $subject, $message, implode("rn", $headers));
echo 'The report has been sent.<br>Thank you for your time.';
}

最新更新