How can PHP be used to customize the content of the email notification based on the user's action?

To customize the content of the email notification based on the user's action in PHP, you can use conditional statements to check the user's action and then dynamically generate the email content accordingly. For example, if the user has made a purchase, you can include details of the purchase in the email notification. If the user has signed up for a newsletter, you can include a welcome message in the email.

// Example code to customize email content based on user's action

$userAction = "purchase"; // This can be dynamically set based on user's action

if($userAction == "purchase"){
    $emailContent = "Thank you for your purchase! Here are the details of your order: [Order Details]";
} elseif($userAction == "newsletter_signup"){
    $emailContent = "Welcome to our newsletter! Stay tuned for updates and promotions.";
}

// Send email with customized content
$to = "recipient@example.com";
$subject = "Notification";
$headers = "From: sender@example.com";
mail($to, $subject, $emailContent, $headers);