# Mail log writer factory config example

**URL:** <https://discourse.laminas.dev/t/mail-log-writer-factory-config-example/1920>\
**Category:** Components & MVC\
**Tags:** laminas-log, laminas-mail\
**Created:** [October 30, 2020, 5:30pm UTC](https://discourse.laminas.dev/t/mail-log-writer-factory-config-example/1920 "2020-10-30T17:30:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Admirau](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/admirau/32/823_2.png) [@Admirau](https://discourse.laminas.dev/u/Admirau)\
**Post date:** [October 30, 2020, 5:30pm UTC](https://discourse.laminas.dev/t/mail-log-writer-factory-config-example/1920/1 "2020-10-30T17:30:48Z")

</div>

I see that there is an open issune on Github regarding missing configuration documentation for factories.

Can I have and example of how to configure the Zend Log Writer Mail factory to be used with SMTP and Gmail?

Here is my config file using only the stream writer now.

```auto
 'psr_log' => [ // <-- NOTE: key change! it's not 'log'
        'default' => [
            'writers' => [
                'stream' => [
                    'name' => 'stream',
                    'priority' => 1,
                    'options' => [
                        'stream' => 'data/log/application.log',
                        'formatter' => [
                            'name' => Simple::class,
                            'options' => [
                                'format' => '%timestamp% %priorityName% (%priority%): %message% %extra%',
                                'dateTimeFormat' => 'c',
                            ],
                        ],
                        'filters' => [
                            'priority' => [
                                'name' => 'priority',
                                'options' => [
                                    'operator' => '<=',
                                    'priority' => Logger::INFO,
                                ],
                            ],
                        ],
                    ],
                ],
            ],
            'processors' => [
                'requestid' => [
                    'name' => RequestId::class,
                ],
            ],
        ],

```

How do I configure Mail log writer here? (assuming I don’t wan’t to instantitate objects right away).

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [October 30, 2020, 8:36pm UTC](https://discourse.laminas.dev/t/mail-log-writer-factory-config-example/1920/2 "2020-10-30T20:36:21Z")

</div>

Hello and welcome to our forums! 😃

> [@Admirau](#):
>
> Can I have and example of how to configure the Zend Log Writer Mail factory to be used with SMTP…

Here is an example for a writer with mail and SMTP transport:

```php
$logger = new Laminas\Log\Logger(
    [
        'writers' => [
            [
                'name' => Laminas\Log\Writer\Mail::class,
                'priority' => Laminas\Log\Logger::INFO,
                'options' => [
                    'subject_prepend_text' => 'Log: ',
                    'mail' => [
                        'from' => 'from@example.com',
                        'to' => 'to@example.com',
                    ],
                    'transport' => [
                        'type' => Laminas\Mail\Transport\Smtp::class,
                        'options' => [
                            'host' => '…',
                            'connection_class' => Laminas\Mail\Protocol\Smtp\Auth\Plain::class,
                            'connection_config' => [
                                'username' => '…',
                                'password' => '…',
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ]
);

$logger->info('Test');

```

The mail writer of laminas-log uses `Laminas\Mail\MessageFactory` to create the message and `Laminas\Mail\Transport\Factory` to create the transport.  
The option keys are translated to method names which means `subject_prepend_text` is mapped to `setSubjectPrependText ` and `from` to `setFrom`. (See available methods of `Laminas\Mail\Message` and `Laminas\Mail\Transport\SmtpOptions`.)

References:

> **[Intro and Usage - laminas-mail - Laminas Docs](https://docs.laminas.dev/laminas-mail/message/intro/)**
>
> Parse, create, store, and send email messages, using a variety of storage and transport protocols.

> **[SMTP Options - laminas-mail - Laminas Docs](https://docs.laminas.dev/laminas-mail/transport/smtp-options/)**
>
> Parse, create, store, and send email messages, using a variety of storage and transport protocols.

> **[Authentication - laminas-mail - Laminas Docs](https://docs.laminas.dev/laminas-mail/transport/smtp-authentication/)**
>
> Parse, create, store, and send email messages, using a variety of storage and transport protocols.

---

<div class="post-metadata">

**Author:** ![Developer\_Account](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/developer_account/32/1161_2.png) [@Developer\_Account](https://discourse.laminas.dev/u/Developer_Account)\
**Post date:** [November 13, 2021, 12:32am UTC](https://discourse.laminas.dev/t/mail-log-writer-factory-config-example/1920/3 "2021-11-13T00:32:25Z")

</div>

Thank you.  
Is there an option to configure the contents of the subject of the message?  
Eg. include the error message in the subject (eg. 404 Not found).

---

<div class="post-metadata">

**Author:** ![makxk](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/makxk/32/1266_2.png) [@makxk](https://discourse.laminas.dev/u/makxk)\
**Post date:** [November 15, 2021, 8:20am UTC](https://discourse.laminas.dev/t/mail-log-writer-factory-config-example/1920/4 "2021-11-15T08:20:57Z")

</div>

Since there’s setSubject() in [Laminas/Mail/Message](https://github.com/laminas/laminas-mail/blob/b9c896edfe4e076440fb6427c47f6164ec4a2424/src/Message.php#L335) I’m taking an educated guess here and say that you could add a ‘subject’ =\> ‘thing’ beneath ‘subject\_prepend\_text’:

```auto
$logger = new Laminas\Log\Logger(
    [
        'writers' => [
            [
                'name' => Laminas\Log\Writer\Mail::class,
                'priority' => Laminas\Log\Logger::INFO,
                'options' => [
                    'subject_prepend_text' => 'Log: ',
                    'subject' => 'thing' //like this
                    'mail' => [
                        'from' => 'from@example.com',
                        'to' => 'to@example.com',
                    ],
                    'transport' => [
                        'type' => Laminas\Mail\Transport\Smtp::class,
                        'options' => [
                            'host' => '…',
                            'connection_class' => Laminas\Mail\Protocol\Smtp\Auth\Plain::class,
                            'connection_config' => [
                                'username' => '…',
                                'password' => '…',
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ]
);

$logger->info('Test');

```

It’s worth noting that I haven’t used that component yet, that’s about what I can do to help you, sorry.
