Is there a specific MIME type that should be used to ensure successful opening of CSV files in Excel when setting headers for download in PHP?

To ensure successful opening of CSV files in Excel when setting headers for download in PHP, it is recommended to use the MIME type "text/csv" or "application/csv" in the header. This helps Excel to recognize the file format correctly and display the data in separate columns.

<?php
// Set headers for CSV file download
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="example.csv"');

// Output CSV data
echo "Name, Age, City\n";
echo "John Doe, 30, New York\n";
echo "Jane Smith, 25, Los Angeles\n";
?>