• elmurza

    (@elmurza)


    Debug Report: Mail Me In – Magic Link Login for WooCommerce

    Issue:
    The “Mail Me In” plugin fails to authenticate users, displaying the error: “This login link is invalid or has expired.” The login link does not work even when clicked immediately after generation.

    Cause:
    The issue originates in the mail_me_in_handle_token_login function, where the $token_data query returns null. This indicates no matching record is found in the ml_mail_me_in_tokens table for the provided email_hash, token_hash, used = 0, and expires_at > current_time('mysql'). The root cause is that the token insertion in mail_me_in_send_link_handler fails, as evidenced by:

    • No records in the ml_mail_me_in_tokens table (confirmed via phpMyAdmin).
    • Absence of Token Inserted: Success/Failed logs, suggesting $wpdb->insert does not execute or fails silently.

    Possible Reasons for Insertion Failure:

    1. Database Error: The ml_mail_me_in_tokens table exists but $wpdb->insert fails due to:
    • Insufficient database permissions (WordPress user lacks INSERT privileges).
    • Table structure issues (e.g., collation mismatch or constraints).
    1. Table Creation Failure: The mail_me_in_create_tokens_table function may not have executed correctly during plugin activation, or the table was not created.
    2. Code Execution Issue: The mail_me_in_send_link_handler function may not be triggered properly due to AJAX issues or server-side restrictions.

    Debug Log Analysis:

    • Logs show:
    • Email: [email protected]
    • Email Hash: 8a1236e567f60301895c6407262a609df95ce54463869564b8b448d4bfb932f2
    • Token Hash: 4811c3095e8cb3d5b3a23b9744d0e45083d8010bbc9a9cb0b23ea92a4467cebd
    • Current Time: 2025-06-07 12:43:19
    • SQL Query: Correct, but no matching record found.
    • Token Data: Empty (null).
    • Missing logs for Token Inserted and Mail Sent, indicating the insertion or AJAX process failed.

    Recommendations:

    1. Verify Table Existence:
    • Check ml_mail_me_in_tokens in phpMyAdmin for structure and presence.
    • Manually run mail_me_in_create_tokens_table() by adding it to the plugin file, refreshing the site, and removing it.
    1. Check Database Permissions:
    • Ensure the WordPress database user has INSERT privileges via hosting panel or phpMyAdmin.
    1. Test Token Insertion:
    • Trigger mail_me_in_send_link_handler and check wp-content/debug.log for Token Inserted: ... and wpdb->last_error.
    1. Verify AJAX and Email:
    • Confirm the AJAX request (wp_ajax_mail_me_in_send_link) executes and wp_mail sends the email.
    1. Timezone Check:
    • Ensure WordPress timezone (Settings > General) matches server time to avoid expires_at issues.

    Next Steps:

    • Provide updated logs containing Token Inserted and Mail Sent entries.
    • Share ml_mail_me_in_tokens table status (exists, structure, or screenshot).
    • Confirm WordPress timezone and database user permissions.

    Date: June 07, 2025

Viewing 1 replies (of 1 total)
  • Plugin Author Amzil Ayoub

    (@amzil000ayoub)

    Thank you for the detailed report! I appreciate you taking the time to document the issue so thoroughly. While I haven’t been able to reproduce this in my production or testing environment, I’d like to help resolve it.

    A few things we can check:

    Database Table Verification
    Could you confirm: The ml_mail_me_in_tokens table exists in the database? Its structure matches this:

    CREATE TABLE ml_mail_me_in_tokens (
    id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    email_hash VARCHAR(255) NOT NULL,
    token_hash VARCHAR(255) NOT NULL,
    used TINYINT(1) DEFAULT 0,
    expires_at DATETIME NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    INDEX (email_hash, token_hash)
    );

    Debugging Steps
    If possible, could you:

    • Add this temporary debug code to your plugin (in the token insertion logic): error_log(print_r($wpdb->last_query, true)); error_log(print_r($wpdb->last_error, true));
    • Check if there are any PHP/Apache error logs on the server.

    Environment Check
    The issue might be environment-specific. Could you share:

    • WordPress version
    • PHP version
    • Any security plugins active (like Wordfence, iThemes Security)
    • Whether this happens on a fresh WordPress install

    Quick Test
    As a temporary workaround, try:

    • Deactivating other plugins
    • Switching to a default theme (Twenty Twenty-Four)
    • Checking if the table creation runs properly by reactivating the plugin

    To help diagnose this efficiently, could you share:

    A URL where the issue occurs, if possible, a staging/test/production environment (no credentials needed). I’ll mimic the process from my side to isolate environment-specific factors.

    Finally, I’ll also review the token insertion logic on my end to ensure there are no edge cases with certain server configurations. Let me know what you find, and I’m happy to provide a patched version if we can identify the root cause.

    Viewing 1 replies (of 1 total)

    The topic ‘The plugin does not fulfill its main task’ is closed to new replies.