XF 2.0 Using emoji in email subject line

AndyB

Well-known member
I would like to be able to include an emoji in the email subject line. In my mail program on my iMac, when I receive the email the subject is not showing the the emoji, instead I see the Unicode codepoint:

pic001.webp

Seams to me the <mail:subject> code in the email template is the problem. Is it possible to show an emoji in the subject line?

Thank you.
 
The subject needs to be encoded correctly and the email client has to support it. You need to look at the source code of your email message to find out if the subject is encoded correctly.

Here is an example of an email source code for subject line starting with an emoji:

Code:
Subject: =?utf-8?Q?=F0=9F=94=A5=C2=A0Buy=20Now=21=20XenForo=20with=20many=20add-ons=21?=
 
Which app do you use for email?

Does this happen with default XF emails too? Such as if you receive a conversation containing an emoji?

We don’t do anything to block them so this is either something on your client, server or within your add-on:

61E0BF9C-F9B7-4903-AB67-E5180D1DE560.webp
 
Does this happen with default XF emails too? Such as if you receive a conversation containing an emoji?

There is a difference between encoding the content and encoding the header lines (subject). You are encoding the content correct for sure, otherwise many foreign language users would have complained.

You would need to test with special characters in a subject to be sure of a correct encoding. But I am also sure it works as it should with regular notification emails.

Maybe the developer would need to encode a subject before putting it into the <mail:subject> in a template? Try:

PHP:
$encodedSubject='=?UTF-8?B?'.base64_encode($subject).'?=';
 
Thank you both for your help.

Chris, I'm using the Mail program that comes with macOS.

I was finally able to make this work by doing this:

PHP:
foreach ($members as $member)
{             
    $mail = \XF::app()->mailer()->newMail();

    $user = \XF::app()->find('XF:User', $member['user_id']);

    $mail->setToUser($user);

    $emoji = "\xF0\x9F\x98\x83";

    $mail->setTemplate('andy_weeklydigest', [
        'threads' => $threads,
        'emoji' => $emoji
    ]);

    $mail->queue();
}


then my email template has the following:
Code:
<mail:subject>
    {$emoji} {{ phrase('weeklydigest_subject') }} ({{ phrase('weeklydigest_from') }} {$xf.options.boardTitle})
</mail:subject>
<snip>

The result in my Mail program when i look at the list of emails:

pic001.webp
 
Back
Top Bottom