<?php
require '../../../vendor/autoload.php';
include('../server/edFunction.php'); 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

function setPassword($to, $userName)
{
    $mail = new PHPMailer(true);
    try {
        $mail->SMTPDebug = 0;
        $mail->isSMTP();

        $setFromName='Watify';
        require_once('/home/jobaaj/public_html/mail_send_credential.php');

        $mail->addAddress($to);
        $mail->isHTML(true);
        $mail->Subject = 'Set Your Password for Watify.io';

        $resetLink = "https://app.watify.io/set-password?email=" . encryptData($to);
        $mail->Body = "<!DOCTYPE html>
<html>
<head>
  <meta charset='UTF-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1'>
  <title>Set Your Password</title>
  <style>
    body { font-family: Arial, sans-serif; text-align: center; }
    .container { max-width: 600px; margin: 0 auto; padding: 20px; }
    .btn { background-color: #0974f1; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; font-size: 16px; font-weight: bold; }
  </style>
</head>
<body>
  <div class='container'>
    <p>Dear $userName,</p>
    <p>You have been granted access to Watify.io by the admin. To complete your account setup, please set your password.</p>
    <p>Click the button below to set your password and activate your account:</p>
    <a href='$resetLink' class='btn'>Set Your Password</a>
    <p>If you did not request this access, please ignore this email.</p>
    <p>For any assistance, feel free to contact our support team at <a href='mailto:support@watify.io'>support@watify.io</a>.</p>
    <p>Best regards,<br>Watify.io Team</p>
  </div>
</body>
</html>";

$mail->AltBody = "Dear $userName,\n\nYou have been granted access to Watify.io by the admin. To complete your account setup, please set your password.\n\nClick the link below to set your password and activate your account:\n$resetLink\n\nIf you did not request this access, please ignore this email.\n\nFor any assistance, contact our support team at support@watify.io.\n\nBest regards,\nWatify.io Team";

        $mail->send();
        // echo "Mail has been sent successfully to $to!";
    } catch (Exception $e) {
        // echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
}

