1and1 Help Centre Categories

print article

Example 3: Copies to Multiple Recipients

This example extends example 2 by sending a copy of the e-mail to each of two different addresses.
For this example, I'll assume that you want the mail sent to both





There are two different ways to do this, and I'm going to show the most secure way. This approach keeps the e-mail addresses out of the HTML, which is desirable because it's common practice for the senders of junk e-mail (SPAM) to collect target e-mail addresses from web sites.

# --------------------------
# Modify these to your own settings. You might have to
# contact your system administrator if you do not run
# your own web server. If the purpose of these
# parameters seems unclear, please see the README file.
$emulate_matts_code= 0;
$secure = 1;
$allow_empty_ref = 1;
$max_recipients = 5;
$mailprog = '/usr/sbin/sendmail -oi -t';
$postmaster = 'fred@your.domain';
@referers = qw(www.your.domain);
@allow_mail_to = ();
@recipients = ();
%recipient_alias = (
'animals' => 'your-name@your.domain,your-name@somewhere-else.domain',
$locale = '';
$charset = 'iso-8859-1';
$date_fmt = '%A, %B %d, %Y at %H:%M:%S';
$style = '/css/nms.css';
$no_content = 0;
$double_spacing = 1;
$wrap_text = 0;
$wrap_style = 1;
$send_confirmation_mail = 0;
$confirmation_text = <<'END_OF_CONFIRMATION';
From: you@your.com
Subject: form submission

Thank you for your form submission.

# ----------------------------
# (no user serviceable parts beyond here)

The lines that have changed from example 1 are:

@allow_mail_to     = (); 

which has changed because the addresses mentioned in %recipient_alias below are automatically allowed, so we don't need to explicitly allow any addresses, and the single %recipient_alias line has become the 3 lines:

%recipient_alias   = (
'animals' => 'your-name@your.domain,your-name@somewhere-else.domain',

which tells FormMail.pl that when you tell it that the recipient is "animals" via a hidden form field,
you really mean that the recipients are those two addresses.

The HTML form now has a hidden "recipient" input with a value of "animals":

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<title>What is your favorite animal ?</title>
<link rel="stylesheet" type="text/css" href="/css/nms.css" />
<form method="post" action="/cgi-bin/FormMail.pl">
<input type="hidden" name="subject" value="Favorite Animal" />
<input type="hidden" name="recipient" value="animals" />
<td>What is your name ?</td>
<td><input type="text" name="name" /></td>
<td>What is your favorite animal ?</td>
<td><input type="text" name="animal" /></td>
<td colspan="2"><input type="submit" /></td>