I found this php script that is called unsubscribe.php. Purpose it to add domain to a blacklist.txt file, from this file domains will be removed manually.
This will be added in email sent through website contact form
Click the following link to unsubscribe: http://www.mywebsite.com/unsubscribe.php?d=%25domain%25
When the user clicks on the email that he received on this domain email than it will open the server page where it will show
Successfully unsubscribed
We apologize for any inconvenience. We will no longer contact you in the future.
It is showing this message but not writing anything to blacklist http://www.mywebsite.com/blacklist.txt
i would be grateful if you can make this code work, I could edit a simple script but i haven’t coded for like 17,18 years and this has certain lines where several steps are combined into 1 line.
This is the script below
THANK YOU
<?php
/*
Upload this file to your webserver and call it e.g. unsubscribe.php
Click the following link to unsubscribe: http://www.mywebsite.com/unsubscribe.php?d=%domain%
add the URL to your $blacklist_filename from below
http://www.mywebsite.com/blacklist.txt
*/
$url_parameter_for_domain="d";
$blacklist_filename="blacklist.txt"; //the filename where it is stored and where the program can access it to read unsubscribed data
//a message given to the user
$message_title="Successfully unsubscribed";
$message_body="We apologize for any inconvenience. We will no longer contact you in the future.";
$message_redirect_url=""; //if set, it will go to this URL after a short time
//------------------ the code starts below -------------
echo "<html><head>";
//check if a special GET parameter is present, if not, set it via javascript and reload
//this prevents that bots will crawl this URL and add domains to the blacklist
if((!isset($_GET['real'])) || ($_GET['real']!="yes")) {
echo "<script>let url=window.location.href;if(url.indexOf('?')>-1){url+='&real=yes'} else {url+='?real=yes'};window.location.href=url;</script>";
} else {
//get domain and validate
$domain=$_GET[$url_parameter_for_domain];
if(($domain!="") && (preg_match('/^(?:[-A-Za-z0-9]+.)+[A-Za-z]{2,6}$/',$domain))) {
file_put_contents($blacklist_filename, $domain."n",FILE_APPEND);
}
}
//output some message
echo " <title>".$message_title."</title>n".
' <meta charset="utf-8">'."n".
' <meta name="viewport" content="width=device-width,initial-scale=1">'."n".
" <style>n".
" *{margin:0; padding:0; box-sizing:border-box;--textcolor:#fff; --bgcolor:#121212; --highlight:#2749c9;}n".
" @media (prefers-color-scheme:dark){*{--textcolor:#141414; --bgcolor:#f0f0f0; --highlight:#ff7f00;}}n".
" body{font-size:18px; font-family:system-ui,sans-serif; line-height:1.4; color:var(--textcolor); background:var(--bgcolor); position:relative; max-width:64em; margin:0 auto;}n".
" header{padding:5vw 5vw 0 5vw; display:flex; flex-wrap:wrap; position:absolute; width:100%; z-index:2;}n".
" header h1{font-size:1em; flex:1;white-space:nowrap; padding:0 5vw .5em 0;}n".
" p,ul,ol,article{max-width:60ch;margin-bottom:.6em;}n".
" </style>n";
if($message_redirect_url!="") echo ' <meta http-equiv="refresh" content="5;url='.$message_redirect_url.'" />'."n";
echo " </head>n".
" <body>n".
" <br><br><h1>".$message_title."</h1>n".
" <br><p>".$message_body."</p>n".
" </body>n".
"</html>";
?>
Earlier it was not working, i made some changes and it seems to open the unsubscribe page but not entering anything in to blacklist.txt file
atul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.