How can PHP be used to notify users via email when files are shared with them on a website?

To notify users via email when files are shared with them on a website, you can use PHP to send an email notification whenever a file is uploaded and shared with a specific user. This can be achieved by setting up a trigger in your file sharing system that calls a PHP script to send an email to the user with the shared file link.

// PHP code to send email notification when a file is shared with a user
$to = "user@example.com";
$subject = "File Shared with You";
$message = "A file has been shared with you on our website. Click the link below to access the file: http://www.example.com/shared_file.pdf";
$headers = "From: webmaster@example.com";

// Send email notification
mail($to, $subject, $message, $headers);