How to Send HTML Emails Using PHP Mail
In order to send HTML emails using the PHP mail() function, it is necessary to modify the email headers and content as follows:
1. Set the "Content-Type" and "MIME-Version" Headers
Change the $headers variable to include the following:
$headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset: utf8\r\n";
2. Enclose the Email Body in HTML Tags
Wrap the $body variable in HTML tags, including a head and body. Ensure that the content type within the head tag specifies UTF-8 encoding.
$body = "<html><head><meta http-equiv='content-type' content='text/html; charset=utf-8' /></head><body><p>
3. Use Inline CSS and Tables
It is recommended to use inline CSS when styling email content. Use tables to create the desired layout.
The final code should look something like this:
Copy after login
This updated code will allow you to send emails with HTML content using the PHP mail() function.
The above is the detailed content of How to send HTML emails using the PHP mail() function?. For more information, please follow other related articles on the PHP Chinese website!