ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\NativeMailerHandler Class Reference

NativeMailerHandler uses the mail() function to send the emails. More...

+ Inheritance diagram for Monolog\Handler\NativeMailerHandler:
+ Collaboration diagram for Monolog\Handler\NativeMailerHandler:

Public Member Functions

 __construct ($to, $subject, $from, $level=Logger::ERROR, $bubble=true, $maxColumnWidth=70)
 
 addHeader ($headers)
 Add headers to the message. More...
 
 addParameter ($parameters)
 Add parameters to the message. More...
 
 getContentType ()
 
 getEncoding ()
 
 setContentType ($contentType)
 
 setEncoding ($encoding)
 
- Public Member Functions inherited from Monolog\Handler\MailHandler
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
bool true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
bool
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 
 reset ()
 

Protected Member Functions

 send ($content, array $records)
 {} More...
 
- Protected Member Functions inherited from Monolog\Handler\MailHandler
 send ($content, array $records)
 Send a mail with the given content. More...
 
 write (array $record)
 {} More...
 
 getHighestRecord (array $records)
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Protected Attributes

 $to
 
 $subject
 
 $headers = array()
 
 $parameters = array()
 
 $maxColumnWidth
 
 $contentType = 'text/plain'
 
 $encoding = 'utf-8'
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

NativeMailerHandler uses the mail() function to send the emails.

Author
Christophe Coevoet stof@.nosp@m.notk.nosp@m..org
Mark Garrett mark@.nosp@m.mode.nosp@m.rndev.nosp@m.elop.nosp@m.erllc.nosp@m..com

Definition at line 23 of file NativeMailerHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\NativeMailerHandler::__construct (   $to,
  $subject,
  $from,
  $level = Logger::ERROR,
  $bubble = true,
  $maxColumnWidth = 70 
)
Parameters
string | array$toThe receiver of the mail
string$subjectThe subject of the mail
string$fromThe sender of the mail
int$levelThe minimum logging level at which this handler will be triggered
bool$bubbleWhether the messages that are handled can bubble up the stack or not
int$maxColumnWidthThe maximum column width that the message lines will have

Definition at line 75 of file NativeMailerHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, $from, Monolog\Handler\AbstractHandler\$level, Monolog\Handler\NativeMailerHandler\$maxColumnWidth, Monolog\Handler\NativeMailerHandler\$subject, Monolog\Handler\NativeMailerHandler\$to, and Monolog\Handler\NativeMailerHandler\addHeader().

76  {
77  parent::__construct($level, $bubble);
78  $this->to = is_array($to) ? $to : array($to);
79  $this->subject = $subject;
80  $this->addHeader(sprintf('From: %s', $from));
81  $this->maxColumnWidth = $maxColumnWidth;
82  }
$from
addHeader($headers)
Add headers to the message.
+ Here is the call graph for this function:

Member Function Documentation

◆ addHeader()

Monolog\Handler\NativeMailerHandler::addHeader (   $headers)

Add headers to the message.

Parameters
string | array$headersCustom added headers
Returns
self

Definition at line 90 of file NativeMailerHandler.php.

References $header, and Monolog\Handler\NativeMailerHandler\$headers.

Referenced by Monolog\Handler\NativeMailerHandler\__construct().

91  {
92  foreach ((array) $headers as $header) {
93  if (strpos($header, "\n") !== false || strpos($header, "\r") !== false) {
94  throw new \InvalidArgumentException('Headers can not contain newline characters for security reasons');
95  }
96  $this->headers[] = $header;
97  }
98 
99  return $this;
100  }
+ Here is the caller graph for this function:

◆ addParameter()

Monolog\Handler\NativeMailerHandler::addParameter (   $parameters)

Add parameters to the message.

Parameters
string | array$parametersCustom added parameters
Returns
self

Definition at line 108 of file NativeMailerHandler.php.

References Monolog\Handler\NativeMailerHandler\$parameters.

109  {
110  $this->parameters = array_merge($this->parameters, (array) $parameters);
111 
112  return $this;
113  }

◆ getContentType()

Monolog\Handler\NativeMailerHandler::getContentType ( )
Returns
string $contentType

Definition at line 142 of file NativeMailerHandler.php.

References Monolog\Handler\NativeMailerHandler\$contentType.

Referenced by Monolog\Handler\NativeMailerHandler\send().

+ Here is the caller graph for this function:

◆ getEncoding()

Monolog\Handler\NativeMailerHandler::getEncoding ( )
Returns
string $encoding

Definition at line 150 of file NativeMailerHandler.php.

References Monolog\Handler\NativeMailerHandler\$encoding.

Referenced by Monolog\Handler\NativeMailerHandler\send().

+ Here is the caller graph for this function:

◆ send()

Monolog\Handler\NativeMailerHandler::send (   $content,
array  $records 
)
protected

{}

Definition at line 118 of file NativeMailerHandler.php.

References Monolog\Handler\NativeMailerHandler\$headers, Monolog\Handler\NativeMailerHandler\$parameters, Monolog\Handler\NativeMailerHandler\$subject, Monolog\Handler\NativeMailerHandler\$to, Monolog\Handler\NativeMailerHandler\getContentType(), Monolog\Handler\NativeMailerHandler\getEncoding(), Monolog\Handler\MailHandler\getHighestRecord(), and Monolog\Handler\mail().

119  {
120  $content = wordwrap($content, $this->maxColumnWidth);
121  $headers = ltrim(implode("\r\n", $this->headers) . "\r\n", "\r\n");
122  $headers .= 'Content-type: ' . $this->getContentType() . '; charset=' . $this->getEncoding() . "\r\n";
123  if ($this->getContentType() == 'text/html' && false === strpos($headers, 'MIME-Version:')) {
124  $headers .= 'MIME-Version: 1.0' . "\r\n";
125  }
126 
128  if ($records) {
129  $subjectFormatter = new LineFormatter($this->subject);
130  $subject = $subjectFormatter->format($this->getHighestRecord($records));
131  }
132 
133  $parameters = implode(' ', $this->parameters);
134  foreach ($this->to as $to) {
135  mail($to, $subject, $content, $headers, $parameters);
136  }
137  }
getHighestRecord(array $records)
Definition: MailHandler.php:56
$records
Definition: simple_test.php:22
mail($to, $subject, $message, $additional_headers=null, $additional_parameters=null)
+ Here is the call graph for this function:

◆ setContentType()

Monolog\Handler\NativeMailerHandler::setContentType (   $contentType)
Parameters
string$contentTypeThe content type of the email - Defaults to text/plain. Use text/html for HTML messages.
Returns
self

Definition at line 160 of file NativeMailerHandler.php.

References Monolog\Handler\NativeMailerHandler\$contentType.

161  {
162  if (strpos($contentType, "\n") !== false || strpos($contentType, "\r") !== false) {
163  throw new \InvalidArgumentException('The content type can not contain newline characters to prevent email header injection');
164  }
165 
166  $this->contentType = $contentType;
167 
168  return $this;
169  }

◆ setEncoding()

Monolog\Handler\NativeMailerHandler::setEncoding (   $encoding)
Parameters
string$encoding
Returns
self

Definition at line 175 of file NativeMailerHandler.php.

References Monolog\Handler\NativeMailerHandler\$encoding.

176  {
177  if (strpos($encoding, "\n") !== false || strpos($encoding, "\r") !== false) {
178  throw new \InvalidArgumentException('The encoding can not contain newline characters to prevent email header injection');
179  }
180 
181  $this->encoding = $encoding;
182 
183  return $this;
184  }

Field Documentation

◆ $contentType

Monolog\Handler\NativeMailerHandler::$contentType = 'text/plain'
protected

◆ $encoding

Monolog\Handler\NativeMailerHandler::$encoding = 'utf-8'
protected

◆ $headers

Monolog\Handler\NativeMailerHandler::$headers = array()
protected

◆ $maxColumnWidth

Monolog\Handler\NativeMailerHandler::$maxColumnWidth
protected

◆ $parameters

Monolog\Handler\NativeMailerHandler::$parameters = array()
protected

◆ $subject

Monolog\Handler\NativeMailerHandler::$subject
protected

◆ $to

Monolog\Handler\NativeMailerHandler::$to
protected

The documentation for this class was generated from the following file: