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
Started 16 years ago by brad | 14 posts |
-
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 # -
So people would choose the recipient from a dropdown list? Or just a simple text box?
MachForm Founder
Posted 16 years ago # -
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 # -
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 idThat would send email to different address based on the selection of a dropdown list.
MachForm Founder
Posted 16 years ago # -
You are an absolute genius Yuniar. I congratulate you on excellent proficiency in PHP and your amazing product.
Cheers :)
Posted 16 years ago # -
Thank you dgrebb :)
MachForm Founder
Posted 16 years ago # -
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 # -
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 # -
Actually there is a better way. Simply comment this line:
$mail->Send();
MachForm Founder
Posted 16 years ago # -
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 # -
Hmm.. interesting, I never thought that way. But yeah, that works.
MachForm Founder
Posted 16 years ago # -
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 # -
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 # -
How about send emails to two or more recipients (multiple selection) and CC to the form submitter?
Posted 16 years ago #
Reply
You must log in to post.