Php 8 mail send html

In PHP 8, you can send an HTML email using the mail() function or a third-party library like SwiftMailer or PHPMailer. Here's an example of how to send an HTML email using the mail() function:

<?php

// Set the email headers
$headers = array(
    'From' => '[email protected]',
    'Reply-To' => '[email protected]',
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/html; charset=UTF-8'
);

// Set the email body
$body = '<html><body><h1>Hello World!</h1><p>This is an HTML email.</p></body></html>';

// Send the email
mail('[email protected]', 'Subject', $body, $headers);

?>

In this example, we set the Content-Type header to text/html to indicate that the email body is in HTML format. We also set the MIME-Version header to 1.0 to specify the version of the MIME standard being used.

Alternatively, you can use a third-party library like SwiftMailer or PHPMailer to send an HTML email. Here's an example of how to send an HTML email using SwiftMailer:

<?php

require_once 'swiftmailer/lib/swift_required.php';

// Create a new SwiftMailer instance
$mailer = new Swift_Mailer(new Swift_SendmailTransport());

// Create a new message
$message = Swift_Message::newInstance('Subject')
    ->setFrom(array('[email protected]' => 'Your Name'))
    ->setTo(array('[email protected]'))
    ->setBody('<html><body><h1>Hello World!</h1><p>This is an HTML email.</p></body></html>', 'text/html');

// Send the message
$mailer->send($message);

?>

In this example, we create a new SwiftMailer instance and use it to create a new message. We set the From and To addresses, as well as the email body, which is an HTML string. We then send the message using the send() method.

Note that in both examples, you'll need to replace the placeholders ([email protected] and [email protected]) with the actual email addresses you want to use.