From 6b2c5a74a3037acad90e3bf651847a04ea50d181 Mon Sep 17 00:00:00 2001 From: Karel Vlk Date: Fri, 30 Aug 2024 18:37:00 +0200 Subject: [PATCH] Message->setBody: Clear headers when adding multi-part body It is undesirable for these headers to remain from a previous single-part call. Solves #265 Signed-off-by: Karel Vlk --- src/Message.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Message.php b/src/Message.php index f0e74840..bb2523c2 100644 --- a/src/Message.php +++ b/src/Message.php @@ -408,12 +408,11 @@ public function setBody($body) // Multipart content headers if ($this->body->isMultiPart()) { - $mime = $this->body->getMime(); - - /** @var ContentType $header */ - $header = $this->getHeaderByName('content-type', ContentType::class); - $header->setType('multipart/mixed'); - $header->addParameter('boundary', $mime->boundary()); + $this->clearHeaderByName('content-type'); + $this->clearHeaderByName('content-transfer-encoding'); + $this->getHeaderByName('content-type', ContentType::class) + ->setType('multipart/mixed') + ->addParameter('boundary', $this->body->getMime()->boundary()); return $this; }