Php html email

A classic combination!

To send an email using PHP and HTML, you'll need to use a combination of PHP's built-in mail() function and some HTML code to format the email content. Here's a basic example to get you started:

PHP Code:

<?php
// Define the email recipient and subject
$to = '[email protected]';
$subject = 'Test Email';

// Define the email body using HTML
$htmlBody = '<html>
  <body>
    <h1>Test Email</h1>
    <p>This is a test email sent using PHP.</p>
  </body>
</html>';

// Define the email headers
$headers = 'MIME-Version: 1.0'. "\r\n";
$headers.= 'Content-type: text/html; charset=UTF-8'. "\r\n";

// Send the email using the mail() function
mail($to, $subject, $htmlBody, $headers);
?>

What's happening:

  1. We define the email recipient ($to) and subject ($subject).
  2. We define the email body using HTML ($htmlBody). In this example, we're using a simple HTML structure with a heading and paragraph.
  3. We define the email headers ($headers) using the MIME-Version and Content-type headers. We set the Content-type header to text/html to indicate that the email body contains HTML content.
  4. We use the mail() function to send the email. The mail() function takes four arguments: the recipient's email address, the subject, the email body, and the headers.

Tips and Variations: