Spartan 117 Posted February 17, 2007 Share Posted February 17, 2007 Hello, I am making a email form and I want just one page to be able to send an email to multiple users. So I am using one of my most used and favorite things in php, query string. I want it to determine who to mail to from the url. If the url is "www.somesite.com/contact.php?jack" I would like an email to be sent to Jack's email address. So here is some code: <?php $Contact_To = $_SERVER['QUERY_STRING']; if ($Contact_To == 'bob') { $Contact_To == 'mynamesbob@site.net'; //Bob's Email... } elseif ($Contact_To == 'jack') { $Contact_To == 'jacksthename@site.net'; //Jack's Email... } elseif ($Contact_To == 'jill') { $Contact_To == 'darkness@site.net'; //Jill's Email... } elseif ($Contact_To == 'bill') { $Contact_To == 'pimpman99@site.net'; //Bill's Email... } elseif ($Contact_To == 'jim') { $Contact_To == '343guiltyspark@site.net'; //Jim's Email... } elseif ($Contact_To == 'john') { $Contact_To == 'crazymofo@site.net'; //John's Email... } else { $Contact_To == 'admin@site.net'; } $email_to = $Contact_To If no name is specified from query string I would like it to send to the admin. I have a problem with the above code and I have no clue how to fix it. This is what I get: Parse error: parse error, unexpected T_FUNCTION in /mnt/w0000/d07/s24/b02a01ae/www/contactus.php on line 30 I had no error and it was working 100% until I changed it to email anyone from the string. (This: $email_to = admin@site.net was all by itself and it worked perfect) Could somebody please help me out? Thanks Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Share Posted February 17, 2007 <?php $Contact_To = $_SERVER['QUERY_STRING']; if ($Contact_To == 'bob') { $Contact_To == 'mynamesbob@site.net'; //Bob's Email... } elseif ($Contact_To == 'jack') { $Contact_To == 'jacksthename@site.net'; //Jack's Email... } elseif ($Contact_To == 'jill') { $Contact_To == 'darkness@site.net'; //Jill's Email... } elseif ($Contact_To == 'bill') { $Contact_To == 'pimpman99@site.net'; //Bill's Email... } elseif ($Contact_To == 'jim') { $Contact_To == '343guiltyspark@site.net'; //Jim's Email... } elseif ($Contact_To == 'john') { $Contact_To == 'crazymofo@site.net'; //John's Email... } else { $Contact_To == 'admin@site.net'; } $email_to = $Contact_To try that Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 The last line doesn't have a ; at the end. Also, == is the comparison operator, = is the assignment. You should use a switch or an array here instead of this big ifelse Fear, what did you change? Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted February 17, 2007 Share Posted February 17, 2007 He has a few syntax errors missing two ' at the end of some. *edit* looks like he fixed it in the main post. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 Which line is 30? And why not use a switch statement? They're much easier to read, and provide the same functionality. (Jesi beat me to that one) Quote Link to comment Share on other sites More sharing options...
Spartan 117 Posted February 17, 2007 Author Share Posted February 17, 2007 I have no idea what a switch statement is. I will go look it up. But It appears that there is a small problem with my contact page. It always sends an email to the admin. This is the entire code: <html> <head><title>Contact EvG¬Clan</title></head> <body> <?php $Contact_To = $_SERVER['QUERY_STRING']; if ($Contact_To == 'bob') { $Contact_To = 'mynamesbob@site.net'; //Bob's Email... } elseif ($Contact_To == 'jack') { $Contact_To = 'jacksthename@site.net'; //Jack's Email... } elseif ($Contact_To == 'jill') { $Contact_To = 'darkness@site.net'; //Jill's Email... } elseif ($Contact_To == 'bill') { $Contact_To = 'pimpman99@site.net'; //Bill's Email... } elseif ($Contact_To == 'jim') { $Contact_To = '343guiltyspark@site.net'; //Jim's Email... } elseif ($Contact_To == 'john') { $Contact_To = 'crazymofo@site.net'; //John's Email... } else { $Contact_To = 'admin@site.net'; } $email_to = $Contact_To; // now this bit is a little bit clever it ASCII encodes // the above email addresss for a link. (@ LINE 102) // It's to help stop spambots from harvesting your email address. function ascii_encode($str){ global $encoded; $encoded=""; for ($i=0; $i < strlen($str); $i++){ $encoded .= '&#'.ord(substr($str,$i)).';'; } return; } // this function just displays the errors, you need a // class ".err" in the css for it to highlight properly. // I've put a little something in above... function err_display($err_array, $err){ if ($err_array["$err"]){ print ("<tr class=err>"); }else{ print ("<tr>"); } } if ($submit){ $err_count = count($err_array); if ($err_count != 0){ print ("<p class=err>Please correct the $err_count error(s):"); while (list($index,$value) = each($err_array)){ print ("$value<br>"); } print ("</p>"); }else{ reset($HTTP_POST_VARS); while (list($key,$val) = each($HTTP_POST_VARS)){ $message .= "$key: $val\n"; print ("$key: $val<br>"); } $email_headers = "From: Possible Future Member\n";//<$email>\n"; $email_subject = "Application"; // this sends the email using the standard php mailer (sendmail?) @mail($email_to, $email_subject, $message, $email_headers); // Here's your thank you note... print ("<h2>Thank you $real_name!</h2>"); } } if (!$submit OR $err_count != "0"){ ascii_encode("$email_to"); print ("<p>Please use the form to send an email to Us</p>"); print ("<form action=\"contact.php\" method=\"POST\">"); print ("<table>\n<tr>"); print ("<td>Name:</td><td><input type=\"text\" size=14 size=14 name=\"Name\" value=\"$real_name\"></td></tr>\n<tr>"); print ("<tr>"); print ("<tr><td>Email:</td><td><input type=\"text\" name=\"Email\" value=\"$e_mail\"></td></tr>\n"); print ("<tr><td>Message:</td><td><textarea name=\"textarea\" cols=\"40\" rows=\"5\" name=\"Message\" value=\"$the_message\"</textarea></td></tr>\n"); print ("<tr><td> </td><td><input name=\"submit\" type=\"Submit\" value=\"Send\"></td></tr>\n"); print ("</table>"); print ("<input type=\"Hidden\" name=\"IP\" value=\"$REMOTE_ADDR\">"); print ("</form>"); } ?> <br> <div align="center"><input type="button" value="Close This Window" onclick="self.close()"></div> </body> </html> I think it has to do with: print ("<form action=\"contact.php\" method=\"POST\">"); That needs to be the same page as I am on, with the query string I am using. But how would I do that? Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 $Contact_To = $_SERVER['QUERY_STRING']; What is that? I think you want $_POST['contact'] or something. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 I'm not sure why Jesi pointed out the difference between "==" and "=" above because you had it correct the first time. The second posting of your code has the incorrect assignment operator ("=") where you want the comparison operator ("==") in your if / else statements. Echo $contact_to to see what it is equal to. Since it is assigning $email_to to the default value, $contact_to isn't equal to what you think it is or should be. Quote Link to comment Share on other sites More sharing options...
Spartan 117 Posted February 17, 2007 Author Share Posted February 17, 2007 $Contact_To = $_SERVER['QUERY_STRING']; What is that? I think you want $_POST['contact'] or something. $Contact_To = $_SERVER['QUERY_STRING']; I do because I know no other way to do this. I just want one page to send a message to a variety of people. contactus.php?spartan117 would send a message to my email address. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 I'm not sure why Jesi pointed out the difference between "==" and "=" above because you had it correct the first time. The second posting of your code has the incorrect assignment operator ("=") where you want the comparison operator ("==") in your if / else statements. Echo $contact_to to see what it is equal to. Since it is assigning $email_to to the default value, $contact_to isn't equal to what you think it is or should be. The first code has this: if ($Contact_To == 'bob') { $Contact_To == 'mynamesbob@site.net'; //Bob's Email... } elseif ($Contact_To == 'jack') { $Contact_To == 'jacksthename@site.net'; //Jack's Email... } elseif ($Contact_To == 'jill') { Which is not correct - he uses == everywhere. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 Yes, you are correct...I must be getting stupider or something...sorry about that Jesi Quote Link to comment Share on other sites More sharing options...
Spartan 117 Posted February 17, 2007 Author Share Posted February 17, 2007 I think I know how to fix it but I don't know how make something = something AND something... lol. Like this: print ("<form action=\"contact.php? & $_SERVER['QUERY_STRING']\" method=\"POST\">"); I think this i what is doing it because when I hit send it just goes to contact.php without the ?jack Quote Link to comment Share on other sites More sharing options...
Spartan 117 Posted February 17, 2007 Author Share Posted February 17, 2007 What I have tried was this: print ("<form action=\"contactus.php?"&& $_SERVER['QUERY_STRING']" \" method=\"POST\">"); But I get an error "unexpected T_CONSTANT_ENCAPSED_STRING" I want action to = contact.php & $_SERVER['QUERY_STRING'] Or maybe just the whole complete url that i am already at. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 The concatenation character in php is a period ( . ). print '<form action="contactus.php?' . $_SERVER['QUERY_STRING'] .'" method="POST">'; Quote Link to comment Share on other sites More sharing options...
Spartan 117 Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks a lot everybody! I finally got it working Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 Well you didn't show us the code for that. But instead of printing the message, print whatever you want.... Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 19, 2007 Share Posted February 19, 2007 The last line doesn't have a ; at the end. Also, == is the comparison operator, = is the assignment. You should use a switch or an array here instead of this big ifelse Fear, what did you change? On his original post he had an ' missing Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.