What are the limitations of including dynamic content, such as the date of email opening, in PHP-generated emails?

Including dynamic content like the date of email opening in PHP-generated emails can be challenging because once the email is sent, the PHP code that generated the email is no longer running. This means that the date of email opening cannot be updated in real-time. One way to work around this limitation is to include a link in the email that, when clicked, triggers a PHP script to update a database with the date and time the email was opened.

// Example PHP code snippet to update the database with the date and time the email was opened
if(isset($_GET['email_id'])) {
    $email_id = $_GET['email_id'];
    $opened_at = date('Y-m-d H:i:s');
    
    // Update the database with the opened_at timestamp
    // $db->query("UPDATE emails SET opened_at = '$opened_at' WHERE id = $email_id");
    
    // Redirect to a thank you page or any other relevant page
    header('Location: thank_you.php');
    exit();
}