PHP code example of nf / mail

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

    

nf / mail example snippets


composer 

"providers"  => [
    ... (Other Provider)
    \NF\Mail\EmailServiceProvider::class
],

define('SENDMAIL_DRIVER', 'wp_mail'); // api, wp_mail, mailchimp (updating). Default is wp_mail

define('EMAIL_USERNAME', '<username>');
define('EMAIL_PASSWORD', '<password>');

	$user_data = [
	    [
	        'email' => '[email protected]',
	        'name'  => 'Name 1'
	    ],
	    [
	        'email' => '[email protected]',
	        'name'  => 'Name 2'
	    ]
	];

	$config = [
		'apiuri'          => '<send email api url>'
	];
	$params = [
	    'variables_1' => 'value_1',
	    'variables_2' => 'value_2',
	];
	$subject = 'No subject';
	$app_id  = 1; 
	$user_id = 1; 

	$email_template = file_get_contents(PATH_FILE_HTML_TEMPLATE);

	$users = collect($user_data);
	$users = $users->map(function($item) use ($params, $subject, $app_id, $user_id){
	    $tmp_user = new \NF\Mail\Models\User();
	    $tmp_user->setName($item['name'])
	             ->setTo($item['email'])
	             ->setAppId($app_id)
	             ->setUserId($user_id)
	             ->setSubject($subject)
	             ->setParams($params);
	    return $tmp_user;
	});

	$email = new \NF\Mail\Email($config);
	$email->send($users, $email_template);