Help with emailing multiple people using powershell

I need to email a file to multiple recipients.  I have been attempting powershell but I keep getting errors saying my parameter 'To' is an empty string.
Here is what I've got:
Function Send-MailMessage {
Param (
[Parameter(`
Mandatory=$true)]
[String]$To,
[Parameter(`
Mandatory=$true)]
[String]$Subject,
[Parameter(`
Mandatory=$true)]
[String]$Body,
[Parameter(`
Mandatory=$true)]
[String]$Password,
[Parameter(`
Mandatory=$true)]
[String]$Attachment
)

$EmailFrom = "FACSRowCount@hbcs.org"
$recipients = @('email1@abc.com', 'email2@abc.com')
$SMTPServer = "mail.abc.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$Att = New-Object System.Net.Mail.Attachment($Attachment)
$SMTPMessage.Attachments.add($Att)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($EmailFrom, $Password);
$SMTPClient.Send($SMTPMessage)
Remove-Variable -Name SMTPClient
Remove-Variable -Name Password

} #End
Send-MailMessage -To $recipients -Subject "Subject" -SmtpServer $SMTPServer -From $EmailFrom -Attachment "c:\abc.txt"

Error:
Send-MailMessage : Cannot bind argument to parameter 'To' because it is an empty string.
+ Send-MailMessage -To $recipients -Subject "Subject" -Smt ...
+                      ~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Send-MailMessage
Brian SandtSystems AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
There's some fundamental thinking errors here. Take the function away first, and then read what you have left.
You will see that $recipients  as well as the other variables are totally NOT DEFINED.
So define it first.

Now from the other perspective, take only the function.
And you'll see you have fixed recipients (and fixed smtp server, etc). Changed it to $To, so that it takes the recipients from your function variable.

And finally, you probably want it to loop through $recipients, so have a for each loop.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shaun VermaakTechnical Specialist/DeveloperCommented:
Without Set-StrictMode defining is not required
strict.pngYou do not want to loop recipients because that will generate multiple emails instead of one
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.