summaryrefslogtreecommitdiffstats
path: root/src/Monolog/Handler/NativeMailerHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Monolog/Handler/NativeMailerHandler.php')
-rw-r--r--src/Monolog/Handler/NativeMailerHandler.php23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/Monolog/Handler/NativeMailerHandler.php b/src/Monolog/Handler/NativeMailerHandler.php
index d7807fd..b597761 100644
--- a/src/Monolog/Handler/NativeMailerHandler.php
+++ b/src/Monolog/Handler/NativeMailerHandler.php
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
/*
* This file is part of the Monolog package.
@@ -38,13 +38,13 @@ class NativeMailerHandler extends MailHandler
* Optional headers for the message
* @var array
*/
- protected $headers = array();
+ protected $headers = [];
/**
* Optional parameters for the message
* @var array
*/
- protected $parameters = array();
+ protected $parameters = [];
/**
* The wordwrap length for the message
@@ -56,7 +56,7 @@ class NativeMailerHandler extends MailHandler
* The Content-type for the message
* @var string
*/
- protected $contentType = 'text/plain';
+ protected $contentType;
/**
* The encoding for the message
@@ -75,7 +75,7 @@ class NativeMailerHandler extends MailHandler
public function __construct($to, $subject, $from, $level = Logger::ERROR, $bubble = true, $maxColumnWidth = 70)
{
parent::__construct($level, $bubble);
- $this->to = is_array($to) ? $to : array($to);
+ $this->to = (array) $to;
$this->subject = $subject;
$this->addHeader(sprintf('From: %s', $from));
$this->maxColumnWidth = $maxColumnWidth;
@@ -115,12 +115,17 @@ class NativeMailerHandler extends MailHandler
/**
* {@inheritdoc}
*/
- protected function send($content, array $records)
+ protected function send(string $content, array $records)
{
- $content = wordwrap($content, $this->maxColumnWidth);
+ $contentType = $this->getContentType() ?: ($this->isHtmlBody($content) ? 'text/html' : 'text/plain');
+
+ if ($contentType !== 'text/html') {
+ $content = wordwrap($content, $this->maxColumnWidth);
+ }
+
$headers = ltrim(implode("\r\n", $this->headers) . "\r\n", "\r\n");
- $headers .= 'Content-type: ' . $this->getContentType() . '; charset=' . $this->getEncoding() . "\r\n";
- if ($this->getContentType() == 'text/html' && false === strpos($headers, 'MIME-Version:')) {
+ $headers .= 'Content-type: ' . $contentType . '; charset=' . $this->getEncoding() . "\r\n";
+ if ($contentType === 'text/html' && false === strpos($headers, 'MIME-Version:')) {
$headers .= 'MIME-Version: 1.0' . "\r\n";
}