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
Sending HTML Email back to submitter
Started 17 years ago by minibigs | 29 posts |
-
Hi,
Just purchased this, nice looking product, playing with it now.
What I would like to do is to send an Email back to the form submitter but with my own HTML (to point to download links, etc) in it.
Any ideas?
Thanks,
Steve.
Posted 17 years ago # -
[UPDATE: This modification applies to version 1.2 only. Version 2 DON'T NEED this.]
Ok, this feature is not currently available out-of-the-box yet.
However, with some tweak, this can be done easily.1) First you'll need to locate the email input name on your form, which you want the email being sent to. To do this, simply view source on your form code. In this sample, my email input name is element_3
2) Edit includes/helper-functions.php, search around line 455, you'll found this code:
$mail->Send(); $mail->ClearAddresses();
Right below those code, add this:
if(function_exists("form{$form_id}_hook_post_email")){ $email_data = call_user_func("form{$form_id}_hook_post_email",$table_data); if(is_array($email_data)){ $mail->Body = $email_data['body']; $mail->Subject = $email_data['subject']; $mail->AddAddress($email_data['target_email']); $mail->Send(); } }
3) Edit hooks/custom_hooks.php, insert this code:
function formXXX_hook_post_email($user_input){ $email_subject = "This is your email subject"; $email_content =<<<EOT ...Put your HTML content here..... EOT; $result['body'] = $email_content; $result['target_email'] = $user_input['element_3']; $result['subject'] = $email_subject; if(!empty($user_input['element_3'])){ return $result; }else{ return true; } }
Replace XXX with your form_id number. Adjust the value of $email_subject and $email_content to fit your need. And also, change element_3 with your own input name, as we get from step 1 above.If all above sounds too difficult, don't worry, paste me the link to your form and I'll try to write the code for you. Or you can just mail me at yuniar [at] appnitro.com
Hope that helps.
MachForm Founder
Posted 17 years ago # -
Will you with the solution above be able to send all the formdata to the submitter?
Posted 16 years ago # -
To send all the form data, you might want to check this thread:
http://www.appnitro.com/forums/topic/how-to-send-a-copy-of-the-form?replies=4MachForm Founder
Posted 16 years ago # -
Thanks :-)
Posted 16 years ago # -
This works perfectly! I have two additional questions:
(1) What would be the syntax to include information entered in one or two of the other form fields in the body of the reply message?
(2) Is it possible to add different auto-responders for different forms? (I've just done my first one so far.) To do that, would I just add a second code block in hooks/custom_hooks.php that references the second form ID?
Thanks in advance.
Brian
Posted 16 years ago # -
1) You can get the information from the form by using this variable: $user_input['XXX'];
Change the XXX with your form element name, for example: $user_input['element_3'];
2) Yes, each of your form could have different auto-responder. Simply add another block in your custom_hooks.php file
MachForm Founder
Posted 16 years ago # -
Yuniar, Thanks for the quick response!
Clearly I don't know what I'm doing - if I just add the variable within the body of the email, for example:
$email_content =<<<EOT
Dear $user_input['element_5'];<br><br> ...I get an error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/cfnjorg/public_html/machform/hooks/custom_hooks.php on line 39
I presume I need to add the variable in a different way ... can you help? Sorry, I'm not too good yet with PHP.
Brian
Posted 16 years ago # -
OK, now I think I've got it. I defined a variable first - for example, $name - using the format you provided, and then used $name within the email body. Happily, it worked!
Brian
Posted 16 years ago # -
Great, that worked.
You could do this too:
$email_content =<<<EOT Dear {$user_input['element_5']}<br><br> ... EOT;
Just put a curly braces between the variable.
MachForm Founder
Posted 16 years ago # -
Thanks. I like that better. I'll give it a try.
Posted 16 years ago # -
The curly brace method works for all variables in my message, except for one that is pulling in the content of a currency field. And it is also complicated by the fact that it is a currency field from which I've eliminated the "cents" element (per another forum topic).
My message has to include the text "... recommending a grant of $[user input amount] for our project ..." -- for example, "... recommending a grant of $2000 for our project ...".
If I use the curly brace method, the user input amount doesn't print in the email message -- only the dollar symbol. If I use my previous method of defining the variable first, for example, as $amount, and then including $$amount in the message body, it prints, but it includes the decimal after the dollar amount, which looks odd.
How can I configure this so that the message will include the amount, with the dollar symbol, but without the decimal?
Thanks in advance.
Posted 16 years ago # -
To escape the $ symbol, you will need to add backslash, like this:
$email_content =<<<EOT recommending a grant of \${$user_input['element_3']} for our project EOT;
If it doesn't work for you, can you paste me your code?MachForm Founder
Posted 16 years ago # -
That did work to display the user input amount with the dollar symbol - thanks!
It is still displaying the decimal point, which I'd like to eliminate. My code in the custom_hooks.php file is exactly like yours above (except it's element_4) - but I had changed the form display to remove the "cents" field, per the instructions in another post. The decimal point does not display in the visible form, but it's included in the email response using the above code. So I get "recommending a grant of $2000. for our next project" rather than "recommending a grant of $2000 for our next project," which would be my preference.
I tried using element_4_1 instead of element_4, but that didn't work when I tested it.
I know it's a small thing, and it may not matter, but is there a way to eliminate the decimal point?
Posted 16 years ago # -
Try this:
$user_input['element_3'] = rtrim($user_input['element_3'],'.'); $email_content =<<<EOT recommending a grant of \${$user_input['element_3']} for our project EOT;
That should remove the decimal point.MachForm Founder
Posted 16 years ago # -
Perfect! Thank you.
Posted 16 years ago # -
Hello,
I followed the instruction and it all worked.
But I don;t know how to call the value of a roll down menu option.
I am getting the option number 1, 2 or 3 instead of the option text value : Option 1, Option 2..$email_content =<<<EOT
Bonjour {$user_input['element_17']}
EOT;Can you help me?
Posted 16 years ago # -
For dropdowns, we need to get the value from other tables first.
Your code should be something like this:
$element_id = 17; $query = "select ~option~ from ap_element_options where form_id='".(int) $_REQUEST['id']."' and element_id='{$element_id}' and option_id='".(int) $user_input['element_'.$element_id]."' and live=1"; $q_result = do_query($query); $row = do_fetch_result($q_result); $element_17_value = $row['option']; $email_content =<<<EOT Bonjour {$element_17_value} EOT;
A bit more complex, so if you have any question, let me know.PS. Replace ~ above with backticks, it doesn't seem to be displayed properly here.
(Edit: the code above has been fixed)
MachForm Founder
Posted 16 years ago # -
Thank you for answering so quick. I tried the code but I get the following error:
select ~option~ from ap_element_options where form_id='29' and element_id='17' and option_id='3' and live=1 Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option~ from ap_element_options where form_id='29' and element_id='17' a' at line 2
Posted 16 years ago # -
I think you forgot to read my PS above ;-)
You need to replace those '~' character into backticks, since backticks can't display well in this forum.
MachForm Founder
Posted 16 years ago #
Reply »
You must log in to post.