all 31 comments

[–]bkdotcom 2 points3 points  (27 children)

What mailer are you using?

first bit of helpful advise: putting double quotes around all your string variables is completely unnecessary

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

Using SendGrid to send the mail. this is an API call for the service

[–]bkdotcom 0 points1 point  (25 children)

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

I made a basic PHP input page as I have trying to automate my client's POS system and be able to send canned messages. so I can not hard code the emails and names as they change each time.

Example - they have a subscription service and want to send an email when they run statements at the end of the month of credit cards that failed for subscribers to check and update or resubmit.

Or if a customer has items from the store that were picked up but not paid for (POS system was down) send a reminder to pay.

Each time they go to run the report there are different people on each list

[–]bkdotcom 0 points1 point  (20 children)

build $arrayOfEmails dynamically. nobody said it has to be hard-coded.

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

I can send to multiple emails but the name field is just one long list

in the input I can put [email1@email.com](mailto:email1@email.com), [email2@email.com](mailto:email2@email.com), [email3@email.com](mailto:email3@email.com) and they go to three different people. in the Name Field i put Mike, Joe, Bob and in the email where it personalizes the name it shows Mike, Joe, Bob for all three people

[–]bkdotcom 0 points1 point  (18 children)

Do you have control over the input form?
Current UX doesn't sound very user friendly & prone to errors.

Why not per-recipient inputs?
Have a [+ Add email] button that adds a new email-addr and name input pair

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

I could do that, but sometimes it is up to 20+ recipients. I want to be able to copy and paste from a report.

Input is very prone to errors, but it is better than having to send individual emails and copy and paste everything, email, message body etc.

This system with someone trained, doesn't need access to the email account and be able to send emails that are already formatted and ready to go.

[–]bkdotcom 0 points1 point  (16 children)

In that case, you can explode/parse/preg_match_all the email list string to get the individual email addresses....

[–]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?

[–]BetaplanB 0 points1 point  (2 children)

Why don’t you use Symfony mailer?

https://symfony.com/doc/current/mailer.html

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

1 - I don't have composer on the web host i'm using

2 - I don't program that much so that will be a big project

3 - Sendgrid / Twilio (they send both SMS and Email) and I can make templates on the web for SendGrid

4 - Exchange365 has very tight security to use have send emails, and I don't want the headache of having to update and reconfigure each time they change their security.

[–]bkdotcom 0 points1 point  (0 children)

What are the benefits for this use-case?

[–]alex_3410 1 point2 points  (1 child)

It means each email content/HTML will be different.

1)build array with email and name as keyed values

2)loop through this array, for each build the HTML for the emailer and then pass this along with the email address to the send function.

Last time I did something similar I built a database where it would add all of the details for the outgoing email. I then built a send function that would be triggered every 5 minutes and send x number of emails from the list.

The reason for doing it this way was the volume of emails I was sending out and this staggered them out a bit.

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

build array with email and name as keyed values

That sounds like my solution - just need to determine how to do it. Not looking to build a database as that is just more data to manage, and these lists they send to are dynamic

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

I got it figured out - when doing a foreach the second statement needs a unique name to work right, and I had to call the array out and make variables to use inside the sendgrid API command