Multiple recipients in FormMail

I'm trying to configure FormMail to send an email to up to 5 different email addresses that are entered in a form by a visitor to my website. I named the variables email1 email2 email3 email4 and email5

I seem to be able to get it to mail to one of the addresses but not the other. Here is the part of the script that I need worked on (I think)

    print MAIL "To: $Config{'email1'}\n";
    print MAIL "From: $Config{'email'} ($Config{'realname'})\n";

How can I get the script to email all 5 recipients? It is also possible that the person who fills out the form might only fill in one or two email addresses. I don't know if that will present any problems.

Thanks in advance for any help.

Tim
timshankAsked:
Who is Participating?
 
tpryorCommented:
Well there will be a lot of guessing going on but here goes.


- if the user filling out the form is specifying the email address ( up to 5 ) to mail to.

- and each email address is on its own field ( meaning it has its own var name ie "email1" in the form "name=email1")

- and those values are stored by name in the hash %Config

then do this...

      # make an array with the mail to var names ie email1, email2, email3 etc
      # in FormMail, anywhere above the part of code that mails, in the same
      # block
      
      @email_to_var_names = ( email1, email2, email3, email4, email5 );
      
      # now loop through them and mail
      
      foreach $email_to ( @email_to_var_names ) {
      
            $email_to = $Config{"$email_to"};
            next if( ! $email_to );    # If no value submitted by user get next
          print MAIL "To: $email_to\n";
          print MAIL "From: $Config{'email'} ($Config{'realname'})\n";
          
          # add rest of email code
          
    } # end of email loop
0
 
ozoCommented:
what is FormMail, what is $Config{'email1'} and what went wrong when you couldn't get mail to the other address?
0
 
serg111Commented:
Make it simple:


print MAIL "To: $Config{'email1'}\n";
print MAIL "CC: $Config{'email2'} $Config{'email3'} $Config{'email4'} $Config{'email5'} $Config{'email6'}\n";
print MAIL "From: $Config{'email'} ($Config{'realname'})\n";

It will send carbon copies (CC) to any number of addresses
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
tpryorCommented:
well it doesnt check if it actually has a value
0
 
ozoCommented:
which may be ok as long as Config{email1} actually has a value
tpryor, if you look at @email_to_var_names after running your routine, you may find that it had an unintended side effect.
you may prefer something like
foreach $email_to ( @Config{email_to_var_names} ){
or
foreach $email_to ( @Config{'email1'..'email5'} ){
0
 
gregreeveCommented:
I have just done this so I know it works:

On the To: line to send to multiple recipients the e-mail addresses must be separated by a comma.  Its that simple.  So a To: line would look like:

print MAIL "To: $Config{'email1'}, $Config{'email2'}, $Config{'email3'}, $Config{'email4'}, $Config{'email5'}, $Config{'email6'}\n";

Problem solved.


0
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.

All Courses

From novice to tech pro — start learning today.