Javitri Posted January 11, 2011 Share Posted January 11, 2011 Hello I am working on php website. Now here im working on sending orders. So once it is ordered the confirmation e-mail goes to one who ordered(he enters his e-mail id manually) and the head of the department(e-mail ids written in code). But now I have put a checkbox that if the person is head of the department he checks the checkbox and e-mail should be sent to him. So how to verify this by checkbox.Can anyone please help me with this. The person should not get 2 e-mails. I hope I was clear in explaining my doubt. If not please do ask me for more explanation. Thank you. Quote Link to comment Share on other sites More sharing options...
punk_runner Posted January 11, 2011 Share Posted January 11, 2011 Checking whether or not a checkbox was checked is easy in PHP. On your HTML page you have the checkbox, I will call mine "send_email"... <input type="checkbox" id="send_email" name="send_email" value="1"> Send me an email On the following PHP page, the one used in the <form action="myscript.php"> tag you will get the value with the POST array like so: $send_email = $_POST['send_email']; Then just check that value if a conditional: if ($send_email) { // send an email to them } else { // don't send an email to them } You may want to grab an email validation script that makes sure it is a valid email address too, and run $_POST['send_email'] through that first, and maybe even sanitize it too, before processing it, just to be safe... Quote Link to comment Share on other sites More sharing options...
punk_runner Posted January 11, 2011 Share Posted January 11, 2011 You could also use these: if (isset($send_email)) { // send email to them } else { // don't send email to them } if (!(empty($send_email))) { // send them email } else { // don't send them email } Quote Link to comment Share on other sites More sharing options...
Javitri Posted January 12, 2011 Author Share Posted January 12, 2011 Thank you very much I will definitely try this code and get back to you. Quote Link to comment Share on other sites More sharing options...
Javitri Posted January 14, 2011 Author Share Posted January 14, 2011 # $departments = array("access"=>"Access Services", # "advancement"=>"Advancement", # "archives"=>"Archives", # "closet"=>"Supply Closet", # "digital"=>"Digital Library Management", # "dmds"=>"DMDS", # "metadata"=>"Metadata Management", # "office"=>"Office of the Dean", # "research"=>"Research & Instruction", # "resourcem"=>"Resource Management", # "resource"=>"Resource Sharing", # "scholarly"=>"Scholarly Resources", # "systems"=>"Systems" , # "others"=>"Other"); # $to = array("access"=>"d.kennedy@edu", # "advancement"=>"m.carpenter@.edu # "archives"=>"j.krizack@edu", # "closet"=>"e.bren@edu", # "digital"=>"p.yott@edu", # "research"=>"j.dendy@edu", # "resourcem"=>"j.morrow@edu", # "resource"=>"br.greene@edu", # "scholarly"=>"a.aaron@edu", # "systems"=>"r.krol@edu",//r.krol # "others"=>"sharma.me@edu"); # # # now after checkbox is verified it sends to head of the department means the e-mail ids listed so how do I write them in if condition. again in if condition how to see whether it goes to that particular head and if not then it should go to both the person who entered his e-mail id and to the head(e-mail ids listed above). Quote Link to comment Share on other sites More sharing options...
punk_runner Posted January 14, 2011 Share Posted January 14, 2011 So for clarification: the head of the departments email address is hard coded into the PHP file and he gets a copy of the email that also goes to the person who ordered the item, correct? But, you want to check if the person who ordered the item is actually the head of the department himself, and set it so that he doesn't get two emails, i.e. one sent to him as the user and one sent to him as the head of the department? I'm also assuming that all of the email addresses listed in your array the various heads of departments, correct? 1. If that is not correct, let me know. 2. If it is, try this code: Assuming that the email address that the user entered was passed to this code through the $_POST['user_email'] variable.... you just need to check if the $user_email address is also in the $to array, and act accordingly: $user_email = $_POST['user_email']; if (in_array($user_email, $to)) { // send only email to $user_email } else { // send email to $user_email // send email to department head } I hope this helps. If not, respond here, I get an email when there is a new response and I am in my studio for the next 10 hours at least. Quote Link to comment Share on other sites More sharing options...
Javitri Posted January 19, 2011 Author Share Posted January 19, 2011 I did work on this but it sends double copy now to both the people the checkbox thing doesnt seem to work. Its like even if I click the checkbox or not it sends 2 copies to both:(:( Can I please have ur e-mail id(if its fine with you) where i can send u both the files. For some reasons I am sorry cannot upload them here. Quote Link to comment Share on other sites More sharing options...
Javitri Posted January 28, 2011 Author Share Posted January 28, 2011 Hi can you please help me figure out what do i need to do further.... I'm still stuck up at the same place 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.