How can PHP be used to format email output in a table for a contact form?
To format email output in a table for a contact form using PHP, you can create an HTML table within the email body and populate it with the form data. This will make the email more structured and easier to read for the recipient. You can use PHP to concatenate the form data into the table format before sending the email.
// Assuming $formData contains the submitted form data
$emailBody = '<table>';
foreach($formData as $key => $value) {
$emailBody .= '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
$emailBody .= '</table>';
// Send email with the formatted table
mail('recipient@example.com', 'Contact Form Submission', $emailBody, 'Content-Type: text/html');