UTF-8 issues causes too long text for database (for from_mail) when using Mime Mail

Created on 6 July 2023, over 1 year ago
Updated 20 October 2023, about 1 year ago

Problem/Motivation

From time to time, an error occurs when trying to send mail via the Batch API, after some time (3-5 hours) when you try to send emails again, the error disappears.

To send emails, I use a view with the output of web form submissions. Ajax is turned off. Other global operations are disabled. Shipments are divided into pages of 100 pieces per page.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'from_mail' at row 1: INSERT INTO "views_send_spool" ("uid", "timestamp", "from_name", "from_mail", "to_name", "to_mail", "subject", "body", "headers") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8);

The SMTP module and "Mime Mail" are also used for the operation of mail on the site

Drupal 9.5.9, PHP 8.1.17, MySQ 8.0.33-0, memory-limit: 1024M, SMTP PHPMailer library 6.8.0, SMTP 8.x-1.2, Mail System 8.x-4.4, Mime Mail 8.x-1.0-alpha5

Steps to reproduce

There are several users working on the site with sending mail, and each time the reasons for the error are unclear. At some point, this error began to appear in my superadministrator mode at the moment when I wanted to send a test email to one test mailbox. The only time I managed to send an email without an error was when changing the letter format from Mime Mail to standard PHP.

Proposed resolution

The error "Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'from_mail' at row 1:" means that when trying to perform an operation in the database in Drupal 9, the data you are trying to save in the column 'from_mail', exceed the maximum allowed length for this column.

This can happen if you are trying to save a row that is too long in the 'from_mail' column, which has a data length limit.

To fix this error, you need to check the length of the data you are trying to store in the 'from_mail' column and make sure that it does not exceed the maximum allowed length for this column. If the data is too long, you may need to shorten it or change the limit on the length of the column in the database.

But interestingly, I always have the same email address for sending - this is the standard mail of the site.

A similar problem is described here: https://www.drupal.org/project/dbee/issues/3334840 🐛 SQL error 1406 Data too long for column 'mail' Fixed

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇷🇺Russia mr.pomelov

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mr.pomelov
  • Status changed to Postponed: needs info about 1 year ago
  • 🇳🇴Norway hansfn

    Thanks for the report. I some how must have missed the notification - sorry.

    Your observation is correct, as the error message says, the module tries to insert a too long text string for the "from_mail" column. However, the (proper) fix is to avoid the situation because it's very clear from the error log that there is some wrong with the handling of UTF-8.

    1. Is it possible to get the error message as plain text, so I can copy the encoded text and see if it is proper UTF-8 or broken?
    2. The 8.x-1.6 version is no longer supported. I assume the problem is the same for 2.0.0-rc1, but it would be nice to get that confirmed.
    3. Are you 100% sure that the from address (name) is always the same? It's weird that it just some times can't handle the UTF-8 (Russian) name.
  • 🇳🇴Norway hansfn

    The only time I managed to send an email without an error was when changing the letter format from Mime Mail to standard PHP

    Yeah, that is a good clue. Will use that to try to reproduce.

  • Status changed to Fixed about 1 year ago
  • 🇳🇴Norway hansfn

    I was able to reproduce the problem, and I fixed it in commit d519b2a8842795459d6363bc721c2a735dcd5e0a.

    You can test it yourself with the dev release or wait for 2.0.0-rc2.

  • 🇷🇺Russia mr.pomelov

    Thanks for the feedback, now there is no way to reproduce this error on a working project, I will wait for 2.0.0-rc2 and try to use it in my work

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024