Home > Backend Development > PHP Tutorial > How to send HTML emails using the PHP mail() function?

How to send HTML emails using the PHP mail() function?

DDD
Release: 2024-11-13 05:53:02
Original
502 people have browsed it

How to send HTML emails using the PHP mail() function?

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";
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template