How can PHP be used to send automated emails for user activation in a login system?
To send automated emails for user activation in a login system using PHP, you can use the PHP `mail()` function to send an email with an activation link to the user's email address. The activation link can contain a unique token that is generated when the user registers. When the user clicks on the activation link, you can verify the token and activate the user's account.
<?php
// Generate a unique activation token
$token = md5(uniqid(rand(), true));
// Send activation email to the user
$to = $user_email;
$subject = 'Activate your account';
$message = 'Click the following link to activate your account: http://example.com/activate.php?token=' . $token;
$headers = 'From: admin@example.com';
mail($to, $subject, $message, $headers);
// Save the activation token in the database for verification
// Update the user record with the activation token