How can I modify my PHP script to send an email when a "delete from" operation is executed?
To send an email when a "delete from" operation is executed in a PHP script, you can use PHP's mail() function to send an email notification. You can place this mail() function call right after the "delete from" operation in your script to ensure that an email is sent whenever a deletion occurs.
<?php
// Perform the delete operation
$query = "DELETE FROM your_table WHERE condition";
$result = mysqli_query($connection, $query);
// Check if the delete operation was successful
if ($result) {
// Send an email notification
$to = "recipient@example.com";
$subject = "Record Deleted";
$message = "A record has been deleted from your_table.";
$headers = "From: your_email@example.com";
mail($to, $subject, $message, $headers);
} else {
echo "Error deleting record: " . mysqli_error($connection);
}
?>
Keywords
Related Questions
- Are there alternative approaches to achieve similar functionality without function overloading in PHP?
- Are there any specific considerations to keep in mind when using session variables in PHP for user authentication?
- What potential security risks are associated with using the exec() function in PHP to execute commands on a server?