unsubscribe.php not adding domain to blacklist.txt. Both files are in root folder of domain

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

New contributor

atul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật