What are the best practices for verifying email addresses in PHP, especially when sending activation links to users?

When sending activation links to users via email, it is important to verify that the email address provided by the user is valid and belongs to them. One common practice is to send a verification email with a unique token or link that the user must click to confirm their email address.

// Generate a unique token
$token = md5(uniqid(rand(), true));

// Save the token in the database along with the user's email address

// Send the verification email
$to = $user_email;
$subject = 'Activate your account';
$message = 'Click the following link to activate your account: http://example.com/activate.php?email=' . $user_email . '&token=' . $token;
$headers = 'From: admin@example.com';
mail($to, $subject, $message, $headers);