/    Sign up×
Community /Pin to ProfileBookmark

Setting up formmail with checkboxes so sends to numerous email addresses

I need to set up a form where, depening upon what checkbox is ticked, the form is sent to a specific email address or email addressses.

For example, if they tick to receive information A, an email is sent to email address A plus a master email address. Or, if they tick to receive information A & B, an email is sent to email address A, email address B plus a master email address.

Is this possible? I’ve been told that javascript has to be added to my form somewhere and somehow but I don’t know where to start. Thanks in advance.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@knowjOct 25.2006 — you can do this all server side with php using the mail() function

one note i should make is not to store the email addresses within the form values.

keep them within the server side code this will reduce/stop spam bots from crawling your email addresses and hammering your account with emails about investments, entering your account details for banks, viagra and longer orgasms
Copy linkTweet thisAlerts:
@The_Little_GuyOct 25.2006 — (Untested)

The Form:
[code=html]<form action="mail.php" method="post">
Subject: <input name="subject" type="text"><br>
Message: <textarea name="message"><br>
Send to: <input type="checkbox" name="send_to" value="A">A
<input type="checkbox" name="send_to" value="B">B

</form>[/code]


Process the Form ([B]mail.php[/B]):
[code=php]<?

$a = "[email protected]";
$b = "[email protected]";
if($_POST['send_to'] == "A"){
$subject = $_POST['subject'];
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$headers .= "From: ".$_POST['name']." rn" . "X-Mailer: PHP/" . phpversion();
$message = 'This is the Message';
$mail = mail("$a", "$subject", $message, $headers);
}
if($_POST['send_to'] == "B"){
$subject = $_POST['subject'];
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$headers .= "From: ".$_POST['name']." rn" . "X-Mailer: PHP/" . phpversion();
$message = $_POST['message'];
$mail = mail("$a", "$subject", $message, $headers);
}

?>[/code]
Copy linkTweet thisAlerts:
@ramsydneyauthorOct 29.2006 — Your answer is brilliant. Thank you so much, I really appreciate your time.

I have a few questions though, I hope you don't mind. I am very, very new to php and previously only used Formmail.

I'm actually not sure where the php code should go? Does it need to be in the same document as the form? If so, does it go above or below the form script? Or should I install the php code as a separate php document in the cgi-bin called form.php???

Do I set up the form as I would have done o using Formmail?

Below is the Formmail script I have been using. My problem is that rather than using a drop down menu I need to be able to use checkboxes so people can select to receive information on more than one topic. Then, based on whatever boxes they tick, the form is sent to specific email addresses.

<form action="/cgi-bin/formmail/formmail.pl" method="POST">

<input type=hidden name="redirect" value="http://www.mywebsite.com.au/thankyou.htm">

<div align="left">

<p>

<input type="hidden" name="subject" value="Web FormMail">

</p>

<p>&nbsp;</p>

<p>Please advise what information you would like to receive </p>

<p>

<select name="recipient">

<option value="[email protected],[email protected]">Village 1

<option value="[email protected],[email protected]">Village 2

<option value="[email protected],[email protected]">Village 3

<option value="[email protected],[email protected]">Village 4

<option value="[email protected],[email protected]">Village 5

</select>

</p>

<p><strong> Contact form</strong><br>

<br>

your name:<br>

<input name="name" size="30" maxlength="30">

</p>

<p>company:<br>

<input name="company" type="text" id="company" size="30" maxlength="30">

</p>

<p> comments:<br>

<textarea wrap="physical" name="comments" cols="30" rows="8"></textarea>

<br>

<br>

<input type="submit" value="send" name="submit">

</p>

</div>

</form>

Thanks again.
×

Success!

Help @ramsydney spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...