<?php require __DIR__ . '/../config.php'; require __DIR__ . '/../vendor/smtp_mailer.php'; $pdo=get_pdo(); $contact=intval($_GET['cid']??0); $token=$_GET['token']??''; if(!$contact){echo 'Invalid';exit;} $conf=get_config(); if(md5($contact.$conf['unsubscribe_secret'])!=$token){echo 'Invalid token';exit;} $stmt=$pdo->prepare('SELECT * FROM list_contacts WHERE id=?'); $stmt->execute([$contact]); $c=$stmt->fetch(); if(!$c){echo 'Not found';exit;} if($c['unsubscribed']){echo 'Already unsubscribed';exit;} $token2 = md5($contact . 'unsub2' . ($conf['unsubscribe_secret'] ?? 'secret_key')); $confirm_url = $conf['base_url'].'/public/confirm_unsubscribe.php?cid='.$contact.'&token='.$token2; $subject='Confirm unsubscribe'; $body="<p>Hello " . htmlspecialchars($c['name']) . ",</p><p>Please confirm your unsubscribe: <a href='".$confirm_url."'>Confirm unsubscribe</a></p>"; send_smtp_mail($conf, $c['email'], $c['name'], $subject, $body); echo 'Confirmation sent.';