Have you tried to get more eyeballs on your CiviCRM bulk mailings but just ended up with some garbage characters instead? As of version 5.23, CiviCRM has supported utf8mb4, the text encoding required to use emoji. Simply put, the text encoding of the database is the way certain "special" characters are stored. (For more on character encoding, see this helpful article). Emoji are special characters defined within a mapping of unicode "code points" as defined by the Unicode Consortium. utf8mb4 stands for 4-Byte UTF-8 Unicode Encoding, as opposed to the previous standard of three-byte encoding. The extra byte makes full emoji use possible by virtue of exponentially expanding the number of code points available.
Without utf8mb4 support in your database, it's possible to add emoji into your mailing as you compose it, only to be disappointed upon sending when those characters become garbled. CiviCRM is sending the text as it's being stored in the database after it is converted from what you enter into the CiviMail interface, WYSIWYG editor, or Mosaico template.
There is now a simple API command to convert your entire database. This function goes table by table through the CiviCRM database and converts the encoding to utf8mb4.
You can call this using the command line or with a standalone PHP script. It's also possible to run this from the API Explorer in the GUI, but with a large database I might be concerned about the operation timing out -- so proceed with extreme caution if you are considering that method. I would not want to run this conversion process without having access to the mysql/Mariadb backend. Also note that currently, utf8mb4 is not the default encoding for CiviCRM so any changes to the database such as custom fields or added extensions may result in tables that need to run this script again or apply this fix, which as of the time of this posting has not been released.
Before attempting, be sure to check your database for the following system prerequisites:
ROW_FORMAT=Dynamic, innodb_large_prefix=true, innodb_file_format=barracuda, innodb_file_per_table=true
Your version of mysql or MariaDB may already have the default encoding set to utf8mb4 in the my.cnf file.
Next, MAKE A BACKUP. Be sure to make a backup of your database before running anything that makes changes to your data en masse. It's always possible the script could fail in the middle of executing, in which case you'll want to restore the backup of the database rather than have a database with different encoding in different, potentially related tables. If you get into trouble, the script does also have a revert mode!
Once you've confirmed your backup is complete, execute the API call. For me, this was as simple as typing
cv api System.utf8conversion
and waiting. There is no debug output, so I also connected to MariaDB to see which commands were running in the process list. For the site I was working on, the script took several minutes to run on the table "civicrm_mailing_event_queue" but that table happens to have several million records. The conversion only took a few minutes total to complete. It also handles log tables if you have the detailed logging setting on.
Once that's done, you should be ready to go! Check out a test mailing with your emoji in the subject line and body of the mailing. It's always a good idea to test any mailing, but particularly ones with special characters you've copied and pasted in, as some platforms like Twitter support custom emoji that may not be translated. As emoji are added to Unicode, some devices may not catch up right away. You can refer to this helpful chart of emojis by date added.
If you are not ready to convert your database, and curious about what CiviCRM's move to utf8mb4 encoding means for your CiviCRM install in the future, you may want to follow this issue in CiviCRM's Gitlab.