Email One Answer Before Survey Submit

More
3 years 5 months ago #102905 by dweisser
dweisser created the topic: Email One Answer Before Survey Submit
Hi LS Folk,
I have searched hi and low for a script that would allow me to:

1) Capture the results of a single question. (This question is a "report" housed in a Text Display question built using Expression Manager and the answers to many previous questions.)
2) Present the Respondent with a button that will send this report via email to their email address.

I've tried using webformmailer and a couple of others that use a script on my server, but I was hoping there was a way to utilize LimeSurvey's mail functions to accomplish this.

Any advice would be most appreciated.
David

Please Log in to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #102906 by supercosh
supercosh replied the topic: Email One Answer Before Survey Submit
Hi David

It is not in my knowledge that the mail api from LS can be used directly in a "high-level" manner out of a survey. I would stick to the solution you allready mentioned: Putting in a link like "mailer.php?survey=123456&token=ABCDEF", the mailer.php script then connects to the LS DB, looks up the token in the corresponding survey table, reads out the answer(s) and sends them to the recipient (=participant identifed by email address in the tables).

If you make the script part of the LS app, it could use the classes from LS in order to issue mails with the correct SMTP settings and so on.

Easier ideas, anyone?

Regards,
Gregor
Last Edit: 3 years 5 months ago by supercosh.

Please Log in to join the conversation.

More
3 years 5 months ago #102907 by dweisser
dweisser replied the topic: Email One Answer Before Survey Submit
Hey - thank you tremendously for your reply.

If you make the script part of the LS app, it could use the classes from LS in order to issue mails with the correct SMTP settings and so on.


It is exactly this which I hope to accomplish, but I haven't the slightest idea of how to go about it.

I would need to attempt some minor formatting for the message as well when it is sent. Also, the the mailer that I abandoned required that the page be refreshed or redirected upon button press. And, I never received my test emails> (#fail).

I'll keep looking for a solution. Thank you.

Please Log in to join the conversation.

More
3 years 5 months ago #102908 by supercosh
supercosh replied the topic: Email One Answer Before Survey Submit
Hi David

LS uses SendEmailMessage() internally, the function is found in /application/helpers/common_helper.php. However, you need to load the Yii Framework in order to use that function.

The function then sends an email using the specified configuration from LimeSurvey.

Be also sure to set the parameter $isHtml to true when you like to send formatted mails - otherwise the email body would get flattened to text-only before sending.

Still a simple solution would be to send the message with PHP's mail() function or by using phpmailer (included with LS). In order to have the page not loaded again, you could make the button open the php script in a popup window, and to be nice also display a message that the mail was sent successfully and that the window may be closed now ;-). If popups are not desired, an AJAX implementation would be required.

Regards,
Gregor

Please Log in to join the conversation.

More
3 years 5 months ago #102909 by dweisser
dweisser replied the topic: Email One Answer Before Survey Submit
I like your thoughts. I am not a programmer; I have little idea about how to actually "call the script", much less edit it. I guess I would put a form button inside a question's text that calls" the script I have somehow" edited to uses phpmailer.

I have some reading to do! Thanks for your thoughtful replies.
David

Please Log in to join the conversation.

More
3 years 5 months ago #102910 by supercosh
supercosh replied the topic: Email One Answer Before Survey Submit
Yes, that's exactly the way to go. Use a "Text display" question, which supports HTML as well as javascript. Build a HTML Form, and put two hidden fields "recipient" and "mailbody" into it - and let the mailbody be filled with the text you allready built with the evaluations. Let the form have "mailer.php" as the form action, and POST as the method and place the "Send E-Mail" Button in the form...

When the from gets submitted to mailer.php, this script does nothing more than sending an email to the recipient parameter with the body parameter.

However, you need to secure the script from being called by anyone who has knowledge of it (spammers). If that's a realistic problem, you could use a simple checksum which is checked in the script. I strongly recommend doing that, but it's not mandatory.

If you need some prof. help in this, you'd be welcome to write me a private message by clicking on my image to the left.

Regards and good luck!
Gregor

Please Log in to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #102911 by dweisser
dweisser replied the topic: Email One Answer Before Survey Submit
Ahh, I think I understand all but one thing. What is the location of the mailer.php.
Do you literally write <form action=" www.mydomain.com/subdirectory/mailer.php ?> Method=post?
I might take you up on the prof offer sometime as well.
Thank you again!
Last Edit: 3 years 5 months ago by dweisser.

Please Log in to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #102913 by supercosh
supercosh replied the topic: Email One Answer Before Survey Submit
Correct, it would look like that:
  <form method="post" action="/myscripts/mailer.php" target="_blank">
    <input type="hidden" name="recipient" value="PUT-EMAIL-ADR-HERE" />
    <input type="hidden" name="body" value="PUT-TEXTBODY-HERE" />
    <input type="submit" value="Send me the results" />
  </form>

Your script then resides in /myscripts and is named mailer.php (or any other name you like to chose). It should check the input parameters in $_POST (recipient and body) in order to send them using the function mail() of PHP.

Regards,
Gregor
Last Edit: 3 years 5 months ago by supercosh.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now