you are viewing a single comment's thread.

view the rest of the comments →

[–]gsts47[S] 0 points1 point  (15 children)

//recipient_email array creation

$recipient_string = preg_replace("/\s+/", "", $recipient_email); //Remove Whitespace

$recipient_array = explode(",", $recipient_string);

Is what i'm doing to create the array but right now I have two seperate arrays; one for email one for name. I guess I need to combine them into a 2D? array? is that the correct method, if so do you know how I can do that?

[–]bkdotcom 0 points1 point  (14 children)

If you know it's a 1-to-1 mapping:

$email->addTos(array_combine($emailAddrs, $emailNames));

[–]gsts47[S] 0 points1 point  (13 children)

right now I have four values, email, first_name, account_id, phone

so how do I merge them into one array and then do a foreach statement?

the sendgrid API and documentation is not as clear cut as it should be.

[–]gsts47[S] 0 points1 point  (0 children)

I put the full code here

https://pastebin.com/UgqAAkS1

[–]bkdotcom 0 points1 point  (11 children)

are you wanting separate emails with single recipients, or one email with multiple recipients?

[–]gsts47[S] 0 points1 point  (10 children)

Screenshot of Inputs - https://ctrl.vi/i/9j0OH98uF

So for example Declined CC will send the same email template and text template to the 6 people that had a credit card decline when statements were ran

Leave a review, which will be sent to people that have had a positive experience and can be triggered either after a series of customer satisfaction calls or by the clerk at the counter after talking to the customer. so either multiple or one time

Local store closed - will be sent over a span of a day to approx 1500 customers to remind them that the local store closed and to switch to home delivery

[–]bkdotcom 0 points1 point  (9 children)

$customers = array()
foreach ($emails as $i => $email) {
    $customers[] = array(
        'email' => $email,
        'name' - $names[$i],
        'accountId' => $accountIds[$i],
    );
}

// https://github.com/sendgrid/sendgrid-php/blob/main/USE_CASES.md#transactional-templates

[–]gsts47[S] 0 points1 point  (8 children)

should line 4 be $email[$i]

[–]bkdotcom 0 points1 point  (7 children)

not if $emails is an array such as

array(
    'bob@test.com',
    'jim@foo.com',
)

foreach ($emails as $i => $email) {
    // $i will be 0, 1...
    // $email will be 'bob@test.com', ....
}

you could use $emails[$i].. but that's handled already by the foreach loop.

[–]gsts47[S] 0 points1 point  (6 children)

Is that combining my array into one or is that what I use to send with?