What are the advantages and disadvantages of using the PHP readfile function for triggering email notifications?
Using the PHP readfile function for triggering email notifications can be advantageous as it allows for easy retrieval and sending of file contents through email. However, it may not be the most efficient method for triggering email notifications as it involves reading the entire file into memory before sending it. This could potentially cause performance issues with large files.
$file = 'file.txt';
$to = 'recipient@example.com';
$subject = 'File attached';
// Read file contents
$content = file_get_contents($file);
// Send email with file attachment
$success = mail($to, $subject, $content);
if($success){
echo 'Email sent successfully';
} else {
echo 'Email sending failed';
}