Ticket #4296 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

wp_mail removes the Content-Type

Reported by: morty Assigned to: rob1n
Priority: high Milestone: 2.3
Component: General Version: 2.2
Severity: major Keywords: has-patch
Cc:

Description

wp_mail() removes the Content-Type. This breaks _all_ plugins not sending text-mails. Content-Type should be filtered just like the From headers.

Attachments

PN_mailfix.php (2.6 kB) - added by morty on 05/19/07 11:17:28.
Plugin which fixes the problem.…
wp_mail-rewrite.diff (6.3 kB) - added by rob1n on 05/28/07 17:52:31.
wp-mail.fix.diff (3.3 kB) - added by rob1n on 06/07/07 00:46:08.
4296.diff (1.2 kB) - added by Nazgul on 06/25/07 21:41:23.

Change History

05/19/07 11:17:28 changed by morty

  • attachment PN_mailfix.php added.

Plugin which fixes the problem....

05/19/07 11:45:10 changed by filosofo

You just need to use the PHPMailer API

$phpmailer->ContentType = "text/plain";

05/19/07 18:50:22 changed by rob1n

Heh...

05/19/07 18:50:38 changed by rob1n

  • owner changed from anonymous to rob1n.
  • status changed from new to assigned.

05/19/07 19:42:16 changed by rob1n

This will fix this ticket and add filters galore.

05/19/07 20:05:50 changed by rob1n

  • keywords set to has-patch.

05/21/07 04:26:40 changed by rob1n

  • keywords changed from has-patch to has-patch commit.

(follow-up: ↓ 8 ) 05/25/07 10:19:30 changed by mattyrob

I'm not 100% sure how phpmailer works but some of this code may be contradictory.

We are checking for Content-Type and setting it as text/plain if it is not set.

However, I have a plugin that passes some mail via wp_mail() that sets the Content-Type as text/html. With his diff the Content-Type will be left alone but the code still invokes $phpmailer->IsHTML( false ); which presumably tells phpmailer that the email isn't html when in fact it is!

Something like this might avoid this problem (if indeed it is still a problem after the patch.

if ( !isset( $content_type ) ) {
	$content_type = 'text/plain'; 
	$phpmailer->IsHTML( false );
} elseif ( isset( $content_type) && ($content_type == 'text/plain' ) {
	$phpmailer->IsHTML( false );
} elseif ( isset( $content_type) && ($content_type == 'text/html' ) {
	$phpmailer->IsHTML( true );
}

(in reply to: ↑ 7 ) 05/26/07 12:51:31 changed by derjohng

... but the code still invokes $phpmailer->IsHTML( false ); which presumably tells phpmailer that the email isn't html when in fact it is!

I have the same problem. My "DJ-Email-Publish" plugin sends the post via wp_mail().

It works not well since 2.2, because wp_mail will be sent HTML mail ($phpmailer->IsHTML( false );).

05/28/07 17:52:31 changed by rob1n

  • attachment wp_mail-rewrite.diff added.

05/28/07 17:53:22 changed by rob1n

Okay, new logic that should fix that issue.

06/02/07 03:18:24 changed by rob1n

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [5639]) wp_mail() rewrite that handles HTML mail. fixes #4296

06/04/07 17:06:47 changed by ryan

I'm getting some reports of funkiness with mail when using the latest from the 2.2 branch.

I'm seeing weird stuff in my comment e-mails - escaped quotes and the
mime info in the msg body.

06/04/07 17:45:46 changed by rob1n

Any examples?

I'll look through the code even so.

06/04/07 17:45:49 changed by rob1n

  • status changed from closed to reopened.
  • resolution deleted.

06/04/07 17:45:52 changed by rob1n

  • keywords deleted.

06/04/07 18:08:36 changed by ryan

Here's an example of mime being in the body. I removed personal info from the headers.

From: xxx
Date: June 4, 2007 10:48:39 AM MDT
To: xxx
Subject: [foo.bar] Comment: "Foo is the new Bar"
Reply-To: xxx

:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="UTF-8"

I asked the original reporters to drop a note on this ticket.

06/06/07 19:12:55 changed by technosailor

Rob1n? ;)

06/07/07 00:06:16 changed by rob1n

I've taken a look through the code, and upon visual inspection I can't find anything faulty, but I'm now going to be running specific debugs and tests.

See where that gets me.

06/07/07 00:46:08 changed by rob1n

  • attachment wp-mail.fix.diff added.

(follow-up: ↓ 19 ) 06/07/07 00:46:47 changed by rob1n

Okay, I found some errors in my coding, but any extra headers I called wp_mail() with, nothing showed up in the body.

How did they call the wp_mail()?

(in reply to: ↑ 18 ) 06/07/07 01:54:59 changed by technosailor

Replying to rob1n:

How did they call the wp_mail()?

I'm not sure I understand the question. Would be happy to provide more info from my end if I know what you are asking for. :)

06/07/07 02:07:17 changed by rob1n

Like, what was the function call and the arguments?

I tried variations on the headers argument, but I still couldn't find the issue of headers in the body.

06/07/07 03:53:39 changed by technosailor

As far as I can tell, it's every instance. For days, any notifications for moderation or new comments all have the weird headers that display into the message itself.

06/08/07 14:24:48 changed by rob1n

Okay, I'm just going to yank this out of 2.2 and leave it in 2.3, where I will commence debugging. The only reason why I put this patch in 2.2 is because the reporter says it breaks HTML emails, but I guess it's plain text for now?

06/08/07 14:27:44 changed by rob1n

(In [5668]) Revert [5639] for 2.2 branch, it's causing problems. see #4296

06/08/07 14:28:11 changed by rob1n

  • milestone changed from 2.2.1 to 2.3 (trunk).

Okay, bumping milestone to 2.3.

06/08/07 18:52:34 changed by mattyrob

Just for information I was getting reports back from some WordPress 2.2 users of my plugin that Content-Type was being added as a header defined as text/plain and was also being added as text in the body of the email as text/html when my plugin was sending HTML emails.

If you want to see who my plugin constructs the emails see the publish (starts at line 327) and mail (starts at line 232) functions here: http://dev.wp-plugins.org/browser/subscribe2/branches/WordPressMuand2.1/subscribe2/subscribe2.php

06/24/07 21:24:53 changed by mattyrob

Further update. I think the issue with my plugin was I was using Content-type with a small 't' whereas the wp_mail looks for Content-Type with a big 'T'. on not finding it the new header is added.

The problem here is that both may be valid depending on which document you read :-( For strict coding though it should bt 'T' - so my bad.

06/25/07 14:29:41 changed by rob1n

I believe those headers are case-sensitive. There was a ticket that I committed in the last month or so that changed all mentions of "Content-type" to "Content-Type" in the WP source.

06/25/07 20:50:25 changed by markjaquith

Like HTTP headers, MIME headers are not case sensitive. See section 1.2.2

WP should be comparing such headers in a case-insensitive way. If we're requiring a header to have a certain type of capitalization, that's a bug!

06/25/07 21:41:23 changed by Nazgul

  • attachment 4296.diff added.

06/25/07 21:45:44 changed by Nazgul

  • keywords set to has-patch.

I've attached a patch which makes the relevant MIME header compares case-insensitive.

I've also made sure that that mime header is actually used, because the current code always adds a Content-Type: text/plain, whatever the input.

06/26/07 19:11:23 changed by markjaquith

(In [5763]) Don't add MIME-Version header twice (PHPMailer already adds it). see #4296

06/26/07 20:18:56 changed by markjaquith

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [5764]) Correctly grab Content-Type from old-school headers, skip blank headers. fixes #4296