Is it possible to simultaneously send an email and insert data into a database using a single script in PHP?

Yes, it is possible to simultaneously send an email and insert data into a database using a single script in PHP. You can achieve this by first inserting the data into the database and then sending an email using PHP's mail function within the same script.

// Connect to your database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Insert data into the database
$query = "INSERT INTO your_table (column1, column2) VALUES ('value1', 'value2')";
mysqli_query($connection, $query);

// Send an email
$to = "recipient@example.com";
$subject = "New Data Inserted";
$message = "New data has been inserted into the database.";
$headers = "From: sender@example.com";
mail($to, $subject, $message, $headers);

// Close the database connection
mysqli_close($connection);