通过 SwiftMailer 发送表情符号

Sending emojis via SwiftMailer

我想通过 SwiftMailer 发送时事通讯,但电子邮件的主题中应该有表情符号。我认为正确的字符集是 utf8mb4 但我怎样才能更改主题的字符集?

它适用于 Swift_Message Class 的正文,因为我定义了如下内容类型:

$message->setBody($html, 'text/html');

PHP 7.0 引入了 Unicode codepoint escape 语法。

This takes a Unicode codepoint in hexadecimal form, and outputs that codepoint in UTF-8 to a double-quoted string or a heredoc. Any valid codepoint is accepted, with leading 0's being optional.

发送主题行的示例 checkmark ✅ Unicode U+2705:

$subject =  "\u{2705}Swift Mailer Dingbat Test Email";

$message = (new Swift_Message($subject))
        ->setFrom([$mail_to_address])
        ->setTo([$mail_from_address])
        ->setBody($html_body, 'text/html');