This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Email from a drop downlist


  1. redityo

    You need do small modification for checkbox. For exmaple you have a checkbox field (element_3) with 3 options, then your options id will be element_3_1, element_3_2, and element_3_3.
    First you need to change the code in "edit/custom-hooks.php" file to be like this :

    function form18_hook_email($params){
    
    	//change the email addresses below
    	$email_list1[1] = 'sales@example.com';
    	$email_list1[2] = 'hrd@example.com';
    	$email_list1[3] = 'support@example.com';
    	$email_list1[4] = 'accounts@example.com';
    	$email_list1[5] = 'legal@example.org'; 
    
    	$res = do_query("select element_3_1,element_3_2,element_3_3 from ap_form_{$params['form_id']}
    where id='{$params['entry_id']}'");
    	$row = do_fetch_result($res);
    
    	//get email for checkbox 1
    	$attn = $row['element_3_1'];
    	if ($attn == '1') {$target_email =  $email_list1[1]  ;}
    
    	//get email for checkbox 2
    	$attn = $row['element_3_2'];
    	if ($attn == '1') {$target_email .= "," .  $email_list1[2]  ;}
    
    	//get email for checkbox 3
    	$attn = $row['element_3_3'];
    	if ($attn == '1') {$target_email .= ",". $email_list1[3]  ;}
    
    	if(!empty($target_email)){
    		return $target_email;
    	}else {
    		return true;
    	}
    }

    after that you need to change the custom code in "includes/helper-functions.php" file from :

    if($target_is_admin){
    
    	if(function_exists("form{$form_id}_hook_email")){
    
    		$carbon_param['form_id'] = $form_id;
    		$carbon_param['entry_id'] = $entry_id;
    		$carbon_email = call_user_func("form{$form_id}_hook_email",$carbon_param);
    
    		if(!empty($carbon_email)){
    				$mail->AddAddress($carbon_email);
    				$mail->Send();
    			}
    		}
    }

    to

    if($target_is_admin){
    
    if(function_exists("form{$form_id}_hook_email")){
    
    	$carbon_param['form_id'] = $form_id;
    	$carbon_param['entry_id'] = $entry_id;
    	$carbon_email = call_user_func("form{$form_id}_hook_email",$carbon_param);
    
    	if(!empty($carbon_email)){
    			$email_address 	= explode(',',$carbon_email);
    
    			foreach ($email_address as $email){
    				$email = trim($email);
    				if(!empty($email)){
    					$mail->AddAddress($email);
    					$has_email = true;
    
    				}
    			}
    			$mail->Send();
    			$mail->ClearAddresses();
    		}
    	}
    }

    MachForm Support

    Posted 14 years ago #
  2. globalipwatch
    Member

    Hello All,

    I hate to add another 'email from a dropdown' question to the forums but after several attempts and many hours of playing with code I still cant get my form setup the way I need to. I asked before and got a really nice reply directing me to other threads but I couldnt get it to work.

    I am SURE other people would like to implement this functionality too. Can anybody confirm if there is another thread that actually answers my question?

    I need to send copies of the form to one person from each of three different groups of people. For example, if i am submitting a repair request, I need to copy 1 engineer from a group of engineers, 1 manager from a group of managers, and 1 accountant from a group of accountants, but the exact person will change each time:

    Dropdown 1 (engineer1, engineer2, engineer3)
    Dropdown 2 (manager1, manager2, manager3)
    Dropdown 3 (accountant1, accountant2, accountant4)

    and thus I need it to be copied to the selection in each dropdown menu.

    Is this possible by just adding multiple email addresses separated by commas to the code for the single dropdown solution?

    this is driving me crazy, after several hours over a few weeks I thought it was time to ask for help

    globalipwatch

    Posted 14 years ago #
  3. globalipwatch
    Member

    Just to followup to my own post, I tried the two drop down list solution generously put out here:

    http://www.appnitro.com/forums/topic/send-form-results-to-specific-email-address-based-on-selected-radio-button?replies=5#post-5712

    I just expanded it for three but it didnt work, here is what i have in custom-hooks

    
    function form7_hook_email($params){
    
    	//email address list for drop down 1
    	$email_list1[1] = 'gmail.com';
    	$email_list1[2] = '@gmail.com';
    	$email_list1[4] = '@gmail.com';
    	$email_list1[5] = '@gmail.com';
    	$email_list1[6] = '@gmail.com';
    
    	//email address list for drop down 2
    	$email_list2[1] = '@gmail.com';
    	$email_list2[4] = '@gmail.com';
    	$email_list2[8] = '@gmail.com';
    	$email_list2[9] = '@gmail.com';
    	$email_list2[10] = '@gmail.com';
    
    	//email address list for drop down 3
    	$email_list3[1] = '@gmail.org';
    	$email_list3[3] = '@gmail.org';
    	$email_list3[4] = '@gmail.org';
    	$email_list3[5] = '@gmail.org';
    	$email_list3[6] = '@gmail.org';
    
    	$res = do_query("select element_8,element_19,element_20 from ap_form_{$params['form_id']}
    where id='{$params['entry_id']}'");
    	$row = do_fetch_result($res);
    
    	//get email for drop down 1
    	$attn = $row['element_19'];
    	$target_email = $email_list1[$attn];
    
    	//get email for drop down 2
    	$attn = $row['element_8'];
    	$target_email .= "," . $email_list2[$attn];
    
    	//get email for drop down 3
    	$attn = $row['element_20'];
    	$target_email .= "," . $email_list3[$attn];
    
    	if(!empty($target_email)){
    		return $target_email;
    	}else {
    		return true;
    	}
    }
    

    and in helper-functions i have

    
    if($target_is_admin){
    
    if(function_exists("form{$form_id}_hook_email")){
    
    	$carbon_param['form_id'] = $form_id;
    	$carbon_param['entry_id'] = $entry_id;
    	$carbon_email = call_user_func("form{$form_id}_hook_email",$carbon_param);
    
    	if(!empty($carbon_email)){
    			$email_address 	= explode(',',$carbon_email);
    
    			foreach ($email_address as $email){
    				$email = trim($email);
    				if(!empty($email)){
    					$mail->AddAddress($email);
    					$has_email = true;
    
    				}
    			}
    			$mail->Send();
                            $mail->ClearAddresses();
    		}
    	}
    }
    
    Posted 14 years ago #
  4. nielsenworld
    Member

    Hi guys!

    I'm trying to send to multiple email from a dropdown, like explained in the beginning of the thread

    But when i click "send" on the review page, I get a 500 internal server error?

    Am I doing something wrong?

    Posted 14 years ago #
  5. nielsenworld
    Member

    Update! - Made it work, my mistake. Works fine! :-)

    Posted 14 years ago #
  6. startagl
    Member

    I hate to beat a dead horse, but...

    I have form [link removed by request]

    I have made to code mods noted and I get the following error.

    Error sending email: Could not instantiate mail function.
    Warning: Cannot modify header information - headers already sent by (output started at /home/apsusinf/public_html/svrrm/apsform/includes/helper-functions.php:503) in /home/apsusinf/public_html/svrrm/apsform/confirm.php on line 38

    I have turned off email notification thinking it was causing the problem, but nope, still fails.

    Thanks.

    Posted 14 years ago #
  7. yuniar

    startagl -- are you having the above problem after doing the modification?


    MachForm Founder

    Posted 14 years ago #
  8. startagl
    Member

    Yes, I was having no problem before the mod. I had to type the email address into the form each time. But then I saw this thread and made the changes.

    Posted 14 years ago #
  9. yuniar

    Hmm.. have you set the email address under "You" section?
    If the problem persist, please send me your file and let me know your machform login info.

    I'll check it.


    MachForm Founder

    Posted 14 years ago #
  10. startagl
    Member

    I had the "You" information set, but then given the nature of the error msg I removed it. I set it again, and tested. I receive the "You" email, and the email of the drop down, but still get the error.

    I have sent you all the files that were described as needing mods. I also sent you the password for machForm.

    Thx

    Posted 14 years ago #
  11. startagl
    Member

    Just to close this out. Yuniar found some corrupt data in my database that caused me to get this error. Thanks Yuniar for your great support.

    Posted 14 years ago #
  12. alchris
    Member

    Yuniar - I was wondering if you have a downloadable or (email) examples to Email from a drop down list and also check boxes. I believe this will help people implement without errors.

    Posted 14 years ago #
  13. yuniar

    alchris -- send us email and we'll send you the files/code as mentioned on the first post.


    MachForm Founder

    Posted 14 years ago #
  14. alfonso
    Member

    I have 3 forms into my site and I use a drop list to select options. Each option goes with an email. All is ok. I have in custom_hooks:

    function form2_hook_email($params){

    //change the email addresses below
    $email_list[1] = 'alfonso@pppppp.es';
    $email_list[2] = 'alfonso@ssssss.es';
    $email_list[3] = 'soft4@ffffffff.org';

    $res = do_query("select element_24 from ap_form_{$params['form_id']}
    where id='{$params['entry_id']}'");
    $row = do_fetch_result($res);

    $attn = $row['element_24'];

    $target_email = $email_list[$attn];

    if(!empty($target_email)){
    return $target_email;
    }else {
    return true;
    }
    }
    function form3_hook_email($params){

    //change the email addresses below
    $email_list[1] = '111111@pppppp.es';
    $email_list[2] = '222222@ssssss.es';
    $email_list[3] = '333333@ffffffff.org';

    .....etc....

    The problem is that I reeciev 2 emails always in each email. If I select in form3 second option then I recieve 2 emails in '222222@ssssss.es'.

    This also happens with email I wrote in "Send notification email to" into the configuration of the form.

    Why I get duplicated emails? Thanks

    Posted 14 years ago #
  15. yuniar

    Hmm... that's weird.
    Are you sure you don't have any duplicated code within helper-functions.php?

    If not can you send me your modified files? We'll check it.
    Please mail to: customer.service [at] appnitro.com


    MachForm Founder

    Posted 14 years ago #
  16. alfonso
    Member

    I have just send you bu email. I modified 2 lines I deleted in helper-functions. Now I only get 1 email to "Send notification..", but still 2 emails to email account I create in custom_hook.

    Thanks

    Posted 14 years ago #
  17. teamwebb2008
    Member

    Beautiful. Works like a dream.

    Posted 14 years ago #
  18. paulcurtis
    Member


    Posted 13 years ago #
  19. paulcurtis
    Member

    Mmmm??? I've implimented the mods. I now get an email receipt as the user would. I get the email of the form to the email address in the Send notification emails to 'you' but not to the person/department in the drop down on my form??

    Any ideas?

    Posted 13 years ago #
  20. yuniar

    Hi Paul,

    Make sure that the $email_list array index is having the same index number as your dropdown. Otherwise, it won't get sent.

    If you have it correct already and still doesn't work, please send us your custom_hooks.php file and let us know the URL to your form. We'll check it.


    MachForm Founder

    Posted 13 years ago #

RSS feed for this topic

Reply »