How can a form action be directed to two different addresses in PHP?

To direct a form action to two different addresses in PHP, you can use JavaScript to submit the form to one address and then use PHP to redirect to the second address after processing the form data. This can be achieved by adding an additional hidden input field in the form to store the second address and then using header() function in PHP to redirect to that address.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data
    
    // Redirect to the first address
    header("Location: first_address.php");
    
    // Redirect to the second address
    $secondAddress = $_POST['second_address'];
    header("Location: $secondAddress");
    exit;
}
?>

<form action="" method="post">
    <!-- Other form fields -->
    <input type="hidden" name="second_address" value="second_address.php">
    <input type="submit" value="Submit">
</form>