PHP code example of dotkernel / dot-mail

1. Go to this page and download the library: Download dotkernel/dot-mail library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dotkernel / dot-mail example snippets



return [
    'dot_mail' => [
        'default' => [
            //...
            'transport' => Laminas\Mail\Transport\Sendmail::class,
            //...
        ]
    ]
]


return [
    'dot_mail' => [
        'default' => [
            //...
            'transport' => Laminas\Mail\Transport\Smtp::class,
            'message_options' => [
                'from' => '',
                //...
            ],
            'smtp_options' => [
                'host' => '',
                'port' => 25,
                'connection_config' => [
                    'username' => '',
                    'password' => '',
                    'ssl' => '',
                ]
            ]
            //...
        ]
    ]
]

public function sendBasicMail()
{
    $this->mailService->setBody('Email body');
    $this->mailService->setSubject('Email subject');
    $this->mailService->getMessage()->addTo('[email protected]', 'User name');
    $this->mailService->getMessage()->setEncoding('utf-8');
    return $this->mailService->send()->isValid();
}

try {
    $this->userService->sendBasicMail();
    $this->messenger->addSuccess('The mail was sent successfully', 'user-login');
    //more code...
} catch (Exception $exception) {
    $this->messenger->addError($exception->getMessage(), 'user-login');
    //more code...
}

$result = $this->mailService->send();
if (! $result->isValid()) {
    //log the error
    error_log($result->getMessage());
}



return [
    'dot_mail' => [
        ...
        'log' => [
            'sent' => getcwd() . '/log/mail/sent.log'
        ]
    ]
];



return [
    'dot_mail' => [
        'default' => [
        ...
            'save_sent_message_folder' => ['INBOX.Sent']
        ],
    ],
];