What steps should be taken to securely delete documents from the server after they have been successfully sent via email to users?

To securely delete documents from the server after they have been successfully sent via email to users, you can use the unlink() function in PHP to remove the file from the server once it has been attached to the email and sent. This ensures that the file is not left accessible on the server after it has served its purpose.

// Code to securely delete the document from the server after sending it via email
$file_path = 'path/to/your/document.pdf'; // Specify the path to the document file

// Send email with attachment

// Delete the file from the server after sending the email
if (file_exists($file_path)) {
    unlink($file_path);
    echo 'File deleted successfully.';
} else {
    echo 'File not found.';
}