Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

nuSendEmail(): Pass an array

Information about updates, news, Code Library
Post Reply
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

nuSendEmail(): Pass an array

Unread post 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.
kev1n
nuBuilder Team
Posts: 3801
Joined: Sun Oct 14, 2018 6:43 pm
nuBuilder Version: 4.5
Has thanked: 2 times
Been thanked: 9 times
Contact:

Re: nuSendEmail(): Pass an array

Unread post 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
Post Reply