Forum Moderators: coopster

Message Too Old, No Replies

help with php script

         

tdjmasteryoda

3:55 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



ok, i'm trying to write a php script..

I need to rig it to where if certain checkboxes are checked it will go to certain e-mails

===========
Ie: If "checkbox 1" is checked form info will go to

"abc1@domain.com"

If "checkbox 2" is checked form info will go to

"xyz1@domain.com"

If both of them are checked, it will send form info to both addresses.
==========

This is very urgent, i could really use your help

Mike12345

4:42 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld, cant really help you, but have you tried hotscripts.com?

Particularly: ht*p://www.hotscripts.com/cgi-bin/search.cgi?bool=AND&query=mail+form&catid=all

You might be able to get a quick freebie from there.

Hopefully someone with more knowledge will be along shortly to help you further.

Best of luck! :)

wruk999

4:54 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



Hi tdjmasteryoda,

In your mail() function, you have a part for your recipients.

If you set this as a variable, ie: $recipients before calling the mail function, then you can do the following:

$recipients = "alwaysreceive@domain.com";

if($checkbox1 == 1) {
$recipients .= "; abc@xyz.com";
}
if($checkbox2 == 1) {
$recipients .= "; cde@vwy.com";
}

Then call the mail function, and in the header section for recipient, just put $recipients

I'm not too sure whether the ; before the email address will work, if not, just have a play around, but I think this is the general idea ;)

wruk999

tdjmasteryoda

6:44 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



here is my script now, i dont think what yall told me works with it.. not sure.. im no expert at this...

<TABLE BORDER=0 cellpadding=0 cellspacing=0><TR><TD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide code from non-js browsers
function validate()
{
formObj = document.contact;
if ((formObj.name.value == "") ¦¦
(formObj.email.value == "") ¦¦
(formObj.subject.value == "") ¦¦
(formObj.msg.value == ""))
{
alert("You have not filled in all required fields.");
return false;
}
else
return true;
}
// end hiding -->
</SCRIPT>


<TABLE BORDER=0 cellpadding=0 cellspacing=0><form action=contact.php method=post name=contact onSubmit="return validate()">
<TR><TD>

<DIV>
1. Name<BR>
<input type=text value='your name' size=50 maxlength=50 name=name class='txtfield'><BR>
<BR>
2. Email Address <BR>
<input type='text' size='50' maxlength='60' name='email'><BR>
<BR>
3. Phone Number<BR>
<input type='text' size='50' maxlength='32' name='phone'><BR>
<BR>
<BR>
4. Club(s) you wish to join.

{{checkboxes would go here}}

<input type='submit' value='Submit'><BR>
</TD></tR></FORM></tABLE>

---------------------------------------------------------

<?

include('header.php');

if ($REQUEST_METHOD == "POST") {

$adminemail = "clubemail@domain.com";
$msg2 = "
Name: $name
Email: $email
Phone: $phone
Message:$msg
";

mail("$adminemail", "Club Name: $subject", "$msg2", "From: $email \nReply-To: $email");
echo " Thank you! Please press the 'back" button on the browser!";

} else {

include('contactform.php');

}

?>

</TD></TR></tABLE>

----------------------------------

this help any?>?

tdjmasteryoda

7:12 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



oh, thought, can i just replace "recipient" with "adminem ail"? as the script is it works great... just it doesnt have $recipient in it...

sorry for being such a dumbass...

masta yoda

tdjmasteryoda

7:19 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



one more thing...

in your explanation

{
if($checkbox1 == 1) {
$recipients = "abc@xyz.com";
}
if($checkbox2 == 1) {
$recipients = "cde@vwy.com";
}

do i have to name my checkboxes

"checkbox1"

"checkbox2"

etc etc?

jatar_k

9:16 pm on Jul 31, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can name them whatever you want just make sure the variable name is exactly the same.

wruk999

9:55 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



If you want to try this and see whether it works ;)
Change the bits in bold, to reflect your name choice of checkboxes.

$adminemail = "clubemail@domain.com";
if($checkbox1 == 1) {
$adminemail .= "; abc@xyz.com";
}
if($checkbox2 == 1) {
$adminemail .= "; cde@vwy.com";
}

$msg2 = "
Name: $name
Email: $email
Phone: $phone
Message:$msg
";

mail("$adminemail", "Club Name: $subject", "$msg2", "From: $email \nReply-To: $email");
echo " Thank you! Please press the 'back" button on the browser!";

wruk999.

tdjmasteryoda

10:18 pm on Aug 4, 2003 (gmt 0)

10+ Year Member



<?

include('header.php');

if ($REQUEST_METHOD == "POST") {

$adminemail = "-------------@yahoo.com";
$msg2 = "
Name: $name
Email: $email
Phone: $phone
Message:$msg";

mail("$adminemail", "Club Registration: $subject", "$msg2", "From: $email \nReply-To: $email");
echo " Thank you! Please press the 'back" button on the browser!";

} else {

{
if($checkbox1 == 1) {
$adminemail = "------------@yahoo.com";
}
if($checkbox2 == 1) {
$adminemail = "------------@comcast.com";
}
{
if($checkbox3 == 1) {
$adminemail = "------------y@hotmail.com";
}
if($checkbox4 == 1) {
$adminemail = "bl------------@hotmail.com";
}
{
if($checkbox5 == 1) {
$adminemail = "j------------17@unt.edu";
}
if($checkbox6 == 1) {
$adminemail = "i------------l_------------s@hotmail.com";
}
{
if($checkbox7 == 1) {
$adminemail = "LL------------e@ev1.net";
}
if($checkbox8 == 1) {
$adminemail = "h------------_luke@yahoo.com";
}
{
if($checkbox9 == 1) {
$adminemail = "f------------4@unt.edu";
}
if($checkbox10 == 1) {
$adminemail = "a------------@unt.edu";
}
{
if($checkbox11 == 1) {
$adminemail = "------------@attbi.com";
}
if($checkbox12 == 1) {
$adminemail = "libe------------e@hotmail.com";
}
{
if($checkbox13 == 1) {
$adminemail = "r.h------------@verizon.net";
}
if($checkbox13 == 1) {
$adminemail = "ro------------1@hotmail.com";
}
{
if($checkbox13 == 1) {
$adminemail = "sa------------86@yahoo.com";
}
if($checkbox14 == 1) {
$adminemail = "d------------ux@yahoo.com";
}
{
if($checkbox15 == 1) {
$adminemail = "z------------@tams.sch.unt.edu";
}
if($checkbox16 == 1) {
$adminemail = "maggie2704@aol.com";
}
{
if($checkbox17 == 1) {
$adminemail = "A------------@adsfds.com";
}
if($checkbox18 == 1) {
$adminemail = "s------------01@unt.edu";
}
{
if($checkbox19 == 1) {
$adminemail = "je------------a@yahoo.com";
}
if($checkbox20 == 1) {
$adminemail = "b------------@hotmail.com";
}
{
include('contactform.php');
}

?>

It doesnt work... why?

here is the contactform.php

--------
<!-- Hide code from non-js browsers function validate() { formObj = document.contact; if ((formObj.name.value == "") ¦¦ (formObj.email.value == "") ¦¦ (formObj.subject.value == "") ¦¦ (formObj.msg.value == "")) { alert("You have not filled in all required fields."); return false; } else return true; } // end hiding -->?

[then my actual form is down here with all the checkboxes and stuff]

tdjmasteryoda

10:20 pm on Aug 4, 2003 (gmt 0)

10+ Year Member



now lets say if i cant get eh checkboxes to work..

how can i have one form send the same data to multiple e-mail address?

{
$adminemail = "blob@blob.com", "blob2@blob.com"
}

?

wruk999

10:28 pm on Aug 4, 2003 (gmt 0)

10+ Year Member



You need to have a . before the = or else it just overwrites what's currently in the variable. Place the dot in, and it will add itself to the variable.

this is how the if statements should look:

}
if($checkbox20 == 1) {
$adminemail .= "b------------@hotmail.com";
}

Does this help?

wruk999

Timotheos

10:38 pm on Aug 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your checkbox values are in the POST then you'll need to move all those if(checkbox) statements before the mail function. The only thing after the else should be the include statement.