humanmade/aws-ses-wp-mail

Sending emails manually error out with white screen (but still sends)

Opened this issue · 4 comments

I'll use WooCommerce as an example - if I go to any given order, and try to resend order emails (specifically, in my testing, I used WooCommerce Subscription renewal notices), the plugin sends the email, BUT - it errors out, simply printing the email it sent to, but everything else is a white screen as WP crashes, here's the output:

array(1) { [0]=> string(18) "customer@email.com" }

If debug mode is on, then it prints this:

Warning: array_merge(): Argument #2 is not an array in /wp-content/plugins/aws-ses-wp-mail/inc/class-ses.php on line 76
and then echoes out the array:
array(1) { [0]=> string(18) "customer@email.com" }

So, my solution to this was to:

ob_start();

at the beginning of the entire plugin (but I'm guessing I could put it at the beginning of the send_wp_mail function, I was just doing this quickly), and then:

ob_end_clean();

at the end of the send_wp_mail() function.

I'm guessing you guys may not have noticed it because you have output buffering ALWAYS on by default, but since some don't - these pieces of code are important.

I never did figure out WHERE the output was coming from since buffering the output was the easiest solution at the time (but removing that output would also fix this issue).

I see a bug here with $headers not correctly being used if it's a string; not sure where that output is though, but doesn't appear to be in the plugin itself.

I couldn't find why it was outputting the array since I just dove into the output buffer fix.

But, there are no problems if I deactivate the plugin and there are no problems if I code the output buffer to catch anything the plugin outputs in that function. Maybe the fact that it's a string is what causes the output (for whatever reason)?

@JoelStickney @rmccue #10 should help, I found that the content type was broken too causing newlines etc to be stripped