Home >Backend Development >PHP Tutorial >How to Send UTF-8 Emails Using PHP?

How to Send UTF-8 Emails Using PHP?

Susan Sarandon
Susan SarandonOriginal
2024-12-20 00:36:09722browse

How to Send UTF-8 Emails Using PHP?

Sending UTF-8 Email with PHP

Sending emails with non-English characters can lead to garbled or missing text. This issue occurs when the email's encoding is not set to UTF-8.

To resolve this, you can add the header "Content-Type: text/html; charset=UTF-8" to your message body.

Using the mail() Function

$headers = "Content-Type: text/html; charset=UTF-8";
mail($to, $subject, $message, $headers);

In this code, $headers is the fourth parameter.

Using PEAR Mail::factory()

$smtp = Mail::factory('smtp', $params);

$headers = ["Content-Type: text/html; charset=UTF-8"];
$mail = $smtp->send($to, $headers, $body);

The above is the detailed content of How to Send UTF-8 Emails Using PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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