• Resolved radgh

    (@radgh)


    As someone mentioned two years ago the email logging feature doesn’t work. By enabling debug mode and going to the log, the errors read:

    WordPress database error: [Table 'examplesite-wp-fitXC5tL.wp_v2p93nzddj_wpre_emails' doesn't exist]
    SELECT * FROM wp_v2p93nzddj_wpre_emails ORDER BY sent_on DESC
    
    WordPress database error: [Table 'examplesite-wp-fitXC5tL.wp_v2p93nzddj_wpre_emails' doesn't exist]
    SELECT * FROM wp_v2p93nzddj_wpre_emails ORDER BY sent_on DESC LIMIT 0,25

    To work around this I set the option wpremail_db_version back to 1001 which looks like it will create the database. But then I get a new error:

    WordPress database error: [Invalid default value for 'sent_on']
    CREATE TABLE IF NOT EXISTS <code>wp_v2p93nzddj_wpre_emails</code> ( <code>id</code> INT UNSIGNED NOT NULL AUTO_INCREMENT, <code>subject</code> VARCHAR(255) NULL, <code>message</code> TEXT NULL, <code>recipients_to</code> TEXT NULL, <code>recipients_cc</code> TEXT NULL, <code>recipients_bcc</code> TEXT NULL, <code>has_attachment</code> TINYINT(1) NOT NULL DEFAULT '0', <code>sent_on</code> DATETIME NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (<code>id</code>)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

    So I edited updateDB1002(), the “sent_on” line 293 (removed backticks to prevent formatting issues):

    Before: sent_on DATETIME NULL DEFAULT CURRENT_TIMESTAMP,

    After: sent_on DATETIME NULL,

    Of course now the date was wrong when emails were sent. So then I edited line 225

    Before: $sql = “INSERT INTO $table_name (subject, message, recipients_to, recipients_cc, recipients_bcc, has_attachment)

    After: $sql = “INSERT INTO $table_name (subject, message, recipients_to, recipients_cc, recipients_bcc, has_attachment, sent_on)

    And finally replaced line 231 with two lines:

    ‘” . (empty($attachments) ? 0 : 1) . “‘,
    ‘” . esc_sql(date(“Y-m-d H:i:s”)) . “‘)”;

    That fixed it. Email log works.

  • The topic ‘Email log does not work, database tables are not created’ is closed to new replies.