Issues

ZF2-177: Zend\Mail\Transport\Sendmail sends duplicate Subject due to adding header and use of mail function

Description

The subject is being added as a header, but also passed in the mailHandler via the php mail function and results in duplicate Subject displayed (at least in Mail in OSX)

protected function prepareHeaders(Message $message)
{
    $headers = $message->headers();

    // On Windows, simply return verbatim
    if ($this->isWindowsOs()) {
        return $headers->toString();
    }

    // On *nix platforms, strip the "to" header
    $headersToSend = new Headers();
    foreach ($headers as $header) {
        if ('To' == $header->getFieldName()) {
            continue;
        }        
        $headersToSend->addHeader($header);
    }
    return $headersToSend->toString();
}

should become:

protected function prepareHeaders(Message $message)
{
    $headers = $message->headers();

    // On Windows, simply return verbatim
    if ($this->isWindowsOs()) {
        return $headers->toString();
    }

    // On *nix platforms, strip the "to" header
    $headersToSend = new Headers();
    foreach ($headers as $header) {
        if ('To' == $header->getFieldName()) {
            continue;
        }
        if ('Subject' == $header->getFieldName()) {
            continue;
        }            
        $headersToSend->addHeader($header);
    }
    return $headersToSend->toString();
}

Comments

Fixed with PR 1034.