diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php
index b2c74a257d24c6667bc9a10be60ad7bb9abac30f..053e216b8a2aa1d56ed829b070885e9291f84ec1 100644
--- a/_test/tests/inc/mailer.test.php
+++ b/_test/tests/inc/mailer.test.php
@@ -7,6 +7,14 @@ class TestMailer extends Mailer {
     public function prop($name){
         return $this->$name;
     }
+
+    public function &propRef($name) {
+        return $this->$name;
+    }
+
+    public function prepareHeaders() {
+        return parent::prepareHeaders();
+    }
 }
 
 class mailer_test extends DokuWikiTest {
@@ -90,5 +98,17 @@ class mailer_test extends DokuWikiTest {
         }
     }
 
+    /**
+     * @see https://forum.dokuwiki.org/post/35822
+     */
+    function test_emptyBCCorCC() {
+        $mail = new TestMailer();
+        $headers = &$mail->propRef('headers');
+        $headers['Bcc'] = '';
+        $headers['Cc'] = '';
+        $header = $mail->prepareHeaders();
+        $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
+        $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Bcc found in headers.');
+    }
 }
 //Setup VIM: ex: et ts=4 :
diff --git a/inc/Mailer.class.php b/inc/Mailer.class.php
index cbd1eb0a9893d216076611e9bd3ced3bc470a00a..f1492be9bc6b09522ae0f49ec694166b40965a8b 100644
--- a/inc/Mailer.class.php
+++ b/inc/Mailer.class.php
@@ -555,6 +555,7 @@ class Mailer {
     protected function prepareHeaders() {
         $headers = '';
         foreach($this->headers as $key => $val) {
+            if ($val === '') continue;
             $headers .= "$key: $val".MAILHEADER_EOL;
         }
         return $headers;