Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Conversation

@MatthiasKuehneEllerhold
Copy link
Contributor

Problem

I want to send emails with html content and a text fallback for client that have HTML disabled or are incabable of it.

I've tried using the documented way for it: zend-mail/multipartalternative-content
and it didnt work in Thunderbird 45.3.0 Mac OS X. I didnt test any other clients though.
Both content (text and html) were displayed, so Thunderbird didnt interpret this as an alternative, but as an attachment. Looking at the source code revealed that the "Content-Type" Header was set 2 times:

Content-Type: multipart/mixed;
 boundary="=_e24aa7041d46737eb2b762f6bfeb2d98"
Content-Type: multipart/alternative

Solution

Changing my code from

$message->getHeaders()->addHeaderLine('Content-Type', 'multipart/alternative');

to

$contentTypeHeader = $message->getHeaders()->get('Content-Type');
$contentTypeHeader->setType('multipart/related');

worked and Thunderbird displays the correct content for the chosen view-mode.

I'm not entirely sure if this is a Thunderbird issue (and the latter Content-Type should overwrite the former) or if this is a bug in zend-mail or just the documentation. If its the latter this PR will fix the documentation.

Used version(s):

zendframework/zend-config                    2.6.0
zendframework/zend-escaper                   2.5.2              
zendframework/zend-eventmanager              3.0.1
zendframework/zend-http                      2.5.5
zendframework/zend-mail                      2.7.1
zendframework/zend-mime                      2.6.0              
zendframework/zend-validator                 2.8.1

@weierophinney
Copy link
Member

Your analysis is correct. addHeaderLine() always creates a GenericHeader instance, instead of the more specific ContentType, which is why this wasn't working correctly previously.

Thanks for the documentation patch!

@weierophinney weierophinney self-assigned this Feb 14, 2017
@weierophinney weierophinney merged commit 6094b90 into zendframework:master Feb 14, 2017
weierophinney added a commit that referenced this pull request Feb 14, 2017
…ader

Fix documentation for setting the correct content-type
weierophinney added a commit that referenced this pull request Feb 14, 2017
weierophinney added a commit that referenced this pull request Feb 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants