How can PHP be used to generate and send activation links for user registration?
To generate and send activation links for user registration in PHP, you can create a unique activation code for each user, store it in the database along with the user's email, and then send an email containing the activation link with the code embedded in it. When the user clicks on the activation link, you can verify the code and activate the user account.
<?php
// Generate a unique activation code
$activationCode = md5(uniqid(rand(), true));
// Store the activation code in the database along with the user's email
// (Assuming $email and $activationCode are already defined)
// $sql = "INSERT INTO users (email, activation_code) VALUES ('$email', '$activationCode')";
// mysqli_query($conn, $sql);
// Send an email containing the activation link
$to = $email;
$subject = 'Activate your account';
$message = 'Click on the following link to activate your account: http://example.com/activate.php?code=' . $activationCode;
$headers = 'From: your@example.com';
mail($to, $subject, $message, $headers);
?>