PHP code example of alaa / magento2-custom-mail

1. Go to this page and download the library: Download alaa/magento2-custom-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/ */

    

alaa / magento2-custom-mail example snippets


$data = [
            'comment' => 'Hello this is a test message',
            'email' => '[email protected]',
            'name' => 'John Doe',
        ];

        /**
         * wrap parameters values in array as they are called by call_user_func_array
         */
        $config = [
            'template_identifier' => ['contact_us'],
            'template_options' => [['area' => Area::AREA_FRONTEND ,'store' => $this->storeManager->getStore()->getId()]],
            'template_vars' => [$data],
            'from' => [['email' => '[email protected]', 'name' => 'John Doe']],
            'to' => ['email' =>'[email protected]', 'name' => 'Tom Right'],
            'cc' => ['email' =>'[email protected]', 'name' => 'Sarah Foxon'],
            'bcc' => ['email' =>'[email protected]', 'name' => 'Ahmed Hassan'],
        ];

        $this->sendMail->setConfig($config);
        $this->sendMail->send();