Setting Header will cause php fatal error
Closed this issue · 3 comments
Hello,
I want to send a normal text/plain message with that code:
$headers = array(
'to' => $emailTo,
'from' => $contactFormData['email'],
'subject' => 'Test',
'Content-type' => 'text/plain'
);
*10718 FastCGI sent in stderr: "PHP message: PHP Fatal error: Call to undefined method ArrayIterator::setType() in /home/matic/localhost/www/xx/skeleton-application/vendor/mtymek/mt-mail/src/ComposerPlugin/PlaintextMessage.php on line 67
Does ist make sense to force the header in that line? Maybe just set it if the message contains both text and html and the user did not set the header.
Nicolas
Hello again,
fix and solution for different bug. I think you forgot to add the boundary to the Multipart/Alternative Content type header. Google Mail did not understand the message with no boundary
So I added this code in the generateTextBody Methode, starting on line 71:
//$event->getMessage()->getHeaders()->get('content-type')->setType('multipart/alternative');
/** @var /Zend/Mail/Message $message */
$message = $event->getMessage();
// TODO: better solution to remove all headers
$message->getHeaders()->removeHeader('Content-Type');
$message->getHeaders()->removeHeader('Content-Type');
$contentTypeHeader = new ContentType();
$contentTypeHeader->setType('multipart/alternative');
$contentTypeHeader->addParameter('boundary',$event->getBody()->getMime()->boundary());
$message->getHeaders()->addHeader($contentTypeHeader);
$event->setMessage($message);
What do you think?
And here the file as gist: https://gist.github.com/traedamatic/af85b56399b4fea0c3bc
You should not set "Content-Type" header manually, as it is handled by MtMail module (BTW, ZF does some magic around it as well).
Bug with missing boundary
is now fixed.