soup-bowl / wp-simple-smtp

📨 WordPress SMTP plugin. Plain and simple.
https://wordpress.org/plugins/simple-smtp
MIT License
24 stars 5 forks source link

Fix headers information not displayed #145

Open benoitchantre opened 1 year ago

benoitchantre commented 1 year ago

When logs are enabled, the information box should display the email headers. This was not the case.

Closes #114.

soup-bowl commented 1 year ago

This seems to break in the scenario when the headers are stored as a string array (triggered by sending a test email).

image

Perhaps it would be helpful to mention what plugin is having problems with mail log display?

benoitchantre commented 1 year ago

Thank you for the feedbacks.

I get PHP warnings from this plugin on many sites when logs are turned on (see #114). Those are maintained sites running the latest version of WP Simple SMTP and WordPress, with PHP 8.0 or PHP 8.1 and MariaDB 10.4

I’ll do more tests.

soup-bowl commented 1 year ago

From reading the WordPress Core code on wp mail, see if this works on an unmodified version. I'm still somewhat operating blind until I know what plugin is causing this.

in src/log/class-log.php line 151

/**
* Gets the server dispatch headers.
*
* @return string|string[]
*/
public function get_headers() {
  if ( ! is_array( $this->headers ) ) {
    return explode( "\n", str_replace( "\r\n", "\n", $this->headers ) );
  } else {
    return $this->headers;
  }
}

I tried your mentioned setup in a Docker environment, and I was not able to replicate the issue - sending a test mail, the headers were a string array.

benoitchantre commented 1 year ago

I wanted to come back earlier but had not time to investigate more. My latest test showed a difference between test emails and regular emails sent by WordPress, but both have valid headers (string or array). Then I did a test with Gravity Forms and saw headers saved in an object instead of an array.

soup-bowl commented 1 year ago

Not a worry. I'll do some digging later with your updated info. The snippet I provided might not work anyway due to how the log object conversion occurs, but I've run out of time to debug at the moment.