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

Emailing results of the form


  1. brad
    Member

    I want to create a number of stock forms that people can choose from. In each of these forms there would be a question asking who do you want to send the results to? Is this possible?

    Basically I want to create an open form that anyone can use and get information sent back to them without having to log into Machform.

    Posted 16 years ago #
  2. yuniar

    So people would choose the recipient from a dropdown list? Or just a simple text box?


    MachForm Founder

    Posted 16 years ago #
  3. ncvettes
    Member

    Either from a dropdown list or to a specific recipient based on a field's input result. Ie, Sales question goes to xxx@xxxx.com, and Support question goes to yyy@xxxx.com

    Posted 16 years ago #
  4. yuniar

    Okay, let say we have a form with id = 3 and the dropdown list is having id = 'element_4' (view the html source of your form to see it).

    Edit your includes/helper-functions.php file. Around line 470 you'll find this code:

    $mail->Send();
    $mail->ClearAddresses();


    Right below that code, insert this code:

    if(function_exists("form{$form_id}_hook_email")){
    	$carbon_email = call_user_func("form{$form_id}_hook_email",$table_data);
    	if(!empty($carbon_email)){
    		$mail->AddAddress($carbon_email);
    		$mail->Send();
    	}
    }


    Next edit your hooks/custom_hooks.php file and insert this code below anywhere:

    function formXXX_hook_email($user_input){
    
    	//change the email addresses below
    	$email_list[1] = 'email1@example.com';
    	$email_list[2] = 'email2@example.com';
    	$email_list[3] = 'email3@example.com'; 
    
    	$attn = $user_input['element_YYY'];
    
    	$target_email = $email_list[$attn];
    
    	if(!empty($target_email)){
    		return $target_email;
    	}else {
    		return true;
    	}
    }


    Adjust the value in that code to match your own form id and dropdown id.

    XXX -> form id
    YYY -> dropdown id

    That would send email to different address based on the selection of a dropdown list.


    MachForm Founder

    Posted 16 years ago #
  5. dgrebb
    Member

    You are an absolute genius Yuniar. I congratulate you on excellent proficiency in PHP and your amazing product.

    Cheers :)

    Posted 16 years ago #
  6. yuniar

    Thank you dgrebb :)


    MachForm Founder

    Posted 16 years ago #
  7. Robye
    Member

    I,ve a question, i used the above system but i want send the form just to the recipient based on the field's input result, not also to the main email of the form (the above way send 2 emails).
    I tryied setting a false email (es. info@mydomain.fals) but its not a good way, undesclosed-recipient come back to my server...
    There's another way to de-active the main email and send just the selected on the form?
    (sorry for my bad english..)

    Posted 16 years ago #
  8. Robye
    Member

    I trying .. in helper-functions.php if i comments at line 452 in this way may work ? :

    /*$email_address = explode(',',$form_email);
    foreach ($email_address as $email){
    $email = trim($email);
    $mail->AddAddress($email);
    }*/

    Posted 16 years ago #
  9. yuniar

    Actually there is a better way. Simply comment this line:

    $mail->Send();


    MachForm Founder

    Posted 16 years ago #
  10. Robye
    Member

    i did it and it works, i added also a new function in the helper-functions.php / c.a line 463, after the commented Send(), to set other forms to act normally (using the default email):

    //$mail->Send(); //disabled

    // start // if there's Not the formXhook_email , acts the 'send()'

    if(!function_exists("form{$form_id}_hook_email")){
    $mail->Send(); // goes
    }

    // end

    It works ... should be correct ? (im not a good programmer...)

    Posted 16 years ago #
  11. yuniar

    Hmm.. interesting, I never thought that way. But yeah, that works.


    MachForm Founder

    Posted 16 years ago #
  12. fredwin
    Member

    As this code changes the includes/helper-functions.php & hooks/custom_hooks.php files, does this mean it would be best to set this up as a seperate folder for the form - if you have multiple forms in use and only this form is to have this feature?

    Posted 16 years ago #
  13. yuniar

    Not necessarily. As long as you change the XXX in formXXX_hook_email with your particular form_id number, then the functionality will be applied to that form only.


    MachForm Founder

    Posted 16 years ago #
  14. acs
    Member

    How about send emails to two or more recipients (multiple selection) and CC to the form submitter?

    Posted 16 years ago #

RSS feed for this topic

Reply