Send HTML Email with PHP and mail()
The PHP mail() function is great for sending plain text emails but it will not send HTML emails without special headers.
Here is a PHP mail() with HTML example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | $body_html = ' <html> <head> <title>HTML Test Email</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p> This is a test. </p> </body> </html> '; $from = 'sender@example.com'; $to = 'recipient@example.com'; $subject = 'HTML Test Email'; $headers = "From:$from\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1"; mail($to, $subject, $body_html, $headers); |
Demo
Demo Send HTML Email with PHP and mail()

Is this part necessary? mail($to, $subject, $body_html, $headers);
Without the mail function the email will not be sent.