How can PHP and HTML be effectively used together for email sending?

To send emails using PHP and HTML, you can use the PHP `mail()` function to send the email with HTML content. You can create an HTML email template with the desired formatting and content, then use PHP to insert dynamic data into the template and send it as an email.

$to = 'recipient@example.com';
$subject = 'Subject of the email';
$message = '
<html>
<head>
  <title>Email Title</title>
</head>
<body>
  <h1>Hello!</h1>
  <p>This is a sample HTML email sent using PHP.</p>
</body>
</html>
';

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Send email
mail($to, $subject, $message, $headers);