?
<?php
ini_set('display_errors', '1');
require 'includes/PHPMailer.php';
require 'includes/SMTP.php';
require 'includes/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
include('db_conn.php');
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = trim($_POST['fullname']);
$phone = trim($_POST['phone']);
$email = trim($_POST['email']);
$city = trim($_POST['city']);
$social = trim($_POST['social']);
$uin = trim($_POST['uin']);
if (!empty($name)) {
$name = ucwords(strtolower($name)); // Capitalize properly
$today = date("Y-m-d"); // Get current date
// Check if already signed
$stmt = $conn->prepare("SELECT COUNT(*) FROM pledge_signed WHERE LOWER(fullname) = LOWER(?)");
$stmt->bind_param("s", $name);
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
$stmt->close();
if ($count > 0) {
echo "<script>alert('You have already signed the Drug Free Pledge. Thank you!'); window.location.href='../pledge_wall.php';</script>";
} else {
// Insert date and name into database
// Insert date and name into database
$stmt = $conn->prepare("INSERT INTO pledge_signed (date, fullname, phone, email, city, social, uin) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssss", $today, $name, $phone, $email, $city, $social, $uin);
$stmt->execute();
$stmt->close();
// ✅ Add your email sending logic here
//Create instance of PHPMailer
$mail = new PHPMailer();
//Set mailer to use smtp
$mail->isSMTP();
//Define smtp host
$mail->Host = "mail.drugfreeproject.org";
//Enable smtp authentication
$mail->SMTPAuth = true;
//Set smtp encryption type (ssl/tls)
$mail->SMTPSecure = "tls";
//Port to connect smtp
$mail->Port = "587";
//Set gmail username
$mail->Username = "info@drugfreeproject.org";
//Set gmail password
$mail->Password = "Drug@free2025";
//Email subject
$mail->Subject = "THE DRUG-FREE PLEDGE";
//Set sender email
$mail->setFrom('info@drugfreeproject.org', 'DRUG FREE PROJECT');
//Enable HTML
$mail->isHTML(true);
//Attachment
//Email body
$mail->Body = "<style>
html,
body {
margin: 0 auto !important;
padding: 0 !important;
height: 100% !important;
width: 100% !important;
font-family: 'Roboto', sans-serif !important;
font-size: 14px;
margin-bottom: 10px;
line-height: 24px;
color: #8094ae;
font-weight: 400;
}
* {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
margin: 0;
padding: 0;
}
table,
td {
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}
table {
border-spacing: 0 !important;
border-collapse: collapse !important;
table-layout: fixed !important;
margin: 0 auto !important;
}
table table table {
table-layout: auto;
}
a {
text-decoration: none;
}
img {
-ms-interpolation-mode:bicubic;
}
</style>
<center style='width: 100%; background-color: #f5f6fa;'>
<table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#f5f6fa'>
<tr>
<td style='padding: 40px 0;'>
<table style='width:100%;max-width:620px;margin:0 auto;'>
<tbody>
<tr>
<td style='text-align: center; padding-bottom:25px'>
<a href='#'><img style='height: 50px' src='https://drugfreeproject.org/logo.png' alt='logo'></a>
</td>
</tr>
</tbody>
</table>
<table style='width:100%;max-width:620px;margin:0 auto;background-color:#ffffff;'>
<tbody>
<tr>
<td style='padding: 30px 30px 15px 30px;'>
<h2 style='font-size: 20px; color: #EA2229; font-weight: 600; margin: 0; text-align:center'>THE DRUG-FREE PLEDGE</h2>
</td>
</tr>
<tr>
<td style='padding: 0 30px 20px;'>
<p style='margin-bottom: 10px; font-size: 14px;'>Dear <b>$name,</b></p>
<p style='margin-bottom: 10px; font-size: 14px; text-align: justify;'>Thank you for taking the bold and inspiring step to <b>pledge a life free from drugs and substance abuse</b>. By signing the <b>Drug-Free Pledge</b>, you have joined a growing movement of Nigerians who are choosing life, love, health, and hope over addiction. You have chosen to stand tall — not just for yourself, but for your family, your community, and the future of our nation.<br><br>
This commitment you’ve made is powerful. It’s a promise to protect your mind, your body, and your dreams. It’s also a message to others: <em>“I choose my future over temporary escape. I choose life over drugs.”</em> As part of this national campaign, you are helping us achieve a bold vision:<br><br>
<b>Reach 20 million Nigerians</b> through outreach and media, <b>Collect 1 million signatures</b> from committed pledge takers like you, <b>Support 100 individuals</b> through their recovery journey, <b>Visit 100 schools</b> and inspire young minds to make the same promise, <b>Build a drug-free culture in schools, homes, workplaces, and communities</b>.<br><br>
You’re not alone on this journey. Together, we’re building a stronger, healthier Nigeria.<br><br>
With gratitude and excitement,<br>
<b><em>Ifeoluwayimika Bamidele</em></b><br>
<em>Chief Impact Officer</em></p><hr>
<p style='margin-bottom: 10px;' align='center'><img style='height: 90px' src='https://drugfreeproject.org/mailcontact.png' alt='Drug Free Project Contact'></p>
</td>
</tr>
</tbody>
</table>
<table style='width:100%;max-width:620px;margin:0 auto;'>
<tbody>
<tr>
<td style='text-align: center; padding:25px 20px 0;'>
<p style='padding-top: 15px; font-size: 12px;'>This email was sent to you for signing the Drug-Free Pledge at <a style='color: #EA2229; text-decoration:none;' href='#'><b>The DRUG FREE PROJECT</b></a>.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</center>";
//Add recipient
$mail->addAddress("$email");
//Finally send email
if ($mail->send() ) {
// Optional: Still save to file
file_put_contents("signatures.txt", $name . PHP_EOL, FILE_APPEND);
echo "<script>window.location.href = 'activate.php?uin=$uin';</script>";
}
}
} else {
echo "<script>alert('Please enter your name.'); window.history.back();</script>";
}
}
$conn->close();
?>