Page 1 of 1

nuSendEmail(): Pass an array

Posted: Tue Sep 27, 2022 5:01 pm
by admin
Instead of passing parameters to nuSendEmail like this:

nuSendEmail('to@test.com','from@test.com','From','Content','Subject', [], true, 'cc_email@test.com', 'bcc_email@test.com')

Pass them using an array:

Code: Select all

nuSendEmail(array(
    'to' => 'to@test.com',
    'cc' => 'cc_email@test.com',
    'bcc' => 'bcc_email@test.com',
    'from_email' => 'from@test.com',
    'from_name' => 'From',
    'body' => 'Content',
    'subject' => 'Subject',
    'attachments' => [] ,
    'html' => true,
    'reply_to' => [] ,
    'priority' => "3"
));
Or with a minimal set of arguments:

Code: Select all

nuSendEmail(array(
    'to' => 'to@test.com',
    'cc' => 'cc_email@test.com',
    'bcc' => 'bcc_email@test.com',
    'body' => 'Content',
    'subject' => 'Subject'
));

The main advantage of "named" arguments is that we can pass the arguments out of their positional order.
Simply put, we don't have to remember the order of parameters.
They also increase the readability of the code.

Re: nuSendEmail(): Pass an array

Posted: Mon Nov 28, 2022 1:46 pm
by kev1n
Pass additional SMTP options to nuSendEmail()

Example:

Code: Select all

$smtpOptions = 
array (
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    ]
);

$link = '<a href="https://www.nubuilder.com/">nuBuilder</a>';

$sendResult = nuSendEmail([
	'to' => 'myemail@something.com',
	'body' => 'test<hr> <b>test html</b> '.$link,
	'subject' => 'test subject',
	'smtp_options' => $smtpOptions
]);
Reference