How can data be formatted on a PHP page to be sent via post method to another page or via email?

To format data on a PHP page to be sent via POST method to another page or via email, you can use the `http_build_query()` function to encode the data into a URL-encoded query string. This function takes an associative array as input and returns a string in the format key1=value1&key2=value2. You can then pass this formatted data as the body of a POST request or as the message body in an email.

// Sample data to be formatted
$data = array(
    'name' => 'John Doe',
    'email' => 'johndoe@example.com',
    'message' => 'Hello, this is a test message.'
);

// Format the data for POST request
$postData = http_build_query($data);

// Send the data via POST method to another page
$ch = curl_init('http://example.com/submit.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
curl_close($ch);

// Send the data via email
$to = 'recipient@example.com';
$subject = 'Test Email';
$headers = 'From: sender@example.com';
$message = http_build_query($data);

mail($to, $subject, $message, $headers);