Check out the LimeSurvey source code on GitHub!

Sending email to an answer to another question.

More
5 years 10 months ago #59679 by Samba
Hi,

We will be conducting this survey over the phone. So the Agent who calls the patient fills in the data.

We would be collectin the email address of the patient througn one of the questions & intend to send an email to them at the end of the survey if the patient says that they would like to recieve a particular tip. (the email will have to be a standard templete with an attachment).

I would like to know as to how this can be executed as what i need is a "send email button" within one of the questions. where the button takes the value of one previous questions (the email question) and sends the said templete.

Please help me as i dont seem to be making much headway in with this. Any other suggestions would be welcome.


Regards,
Samba

Please Log in to join the conversation.

More
5 years 10 months ago #59737 by tpartner
You may need to create a separate PHP file to send the emails and then put a "Send Mail" button in a boilerplate question that uses the jQuery .get() function to pass the email address to the PHP file and fires its script.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 10 months ago #59812 by DenisChenu
Hello,

Maybe you can have a look to catisurvey :
www.crium.univ-metz.fr/gestion/catisurvey/

I never use it, but i think it can be use easily with phone system :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
5 years 10 months ago #59849 by Samba
Thanks to both of you for your replies,

@tpartner - I think i understand what you are saying as i did use a similar function with {INSERTANS} to fit in my "send SMS API".

But dont really know how to generate a php script for sending the mails. (I have no programming experience) or even for that matter where to place the script or where to insert the {INSERTANS} in this case.

Is there any example or something that u can give me for your solution

@Shnoulle - I am doing this project for a NGO so the callers are just volunteers and not trained people so the solution you gave is very difficult for me to implement. as we cannot give them any back end access. Also the email IDs are will be added newly with every participant and will be large in numbers.

regards,
Samba

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #59878 by tpartner
There are some details on PHP mail scripts here - www.w3schools.com/PHP/php_mail.asp

I am NOT a PHP developer so this may be full of security holes but this is a little test script I use on a local machine. Save it as mailTest.php in your template folder.
<?php
 
	$name = $_GET["name"];
	if(!$name) {
		$name = 'sir or madam';
	}
	$age = $_GET["age"];
	if(!$age) {
		$age = 'unknown';
	}
	$msg = 'Dear '.$name.' your age is '.$age.'!';
 
	$address = $_GET["address"];
	if(!$address) {
		$address = 'yourname@yoursite.com';
	}
	$subject = 'A mail test from localhost';
	$body = $msg;
 
	mail($address,$subject,$body); 
?>

Then the source of the boilerplate question could look something like:
<input type="button" value="Send an email" class="emailButton" />
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		$('.emailButton').click(function (event) { 
 
			var mailAddress = '{INSERTANS:11111X22X33}';
 
			if(mailAddress == '') {
				alert ('No email address!');
				return;
			}
			else {
				$.get('upload/templates/yourTemplate/mailTest.php', { address: mailAddress, name: 'John Doe', age: '38' } );
			}
		});
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 10 months ago by tpartner. Reason: Typo
The following user(s) said Thank You: Samba

Please Log in to join the conversation.

More
5 years 9 months ago - 5 years 9 months ago #60197 by Samba
Hey thanks,

I finally managed to get the desired output (by investing a lot of time and logic). so i thought i'd share it.

Create a boilerplate question
<script language="javascript">
 
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
 
var http = createRequestObject();
 
function sendemail() {
	var emailaddress = document.limesurvey.emailaddress.value;
	document.limesurvey.send.disabled=true; 
	document.limesurvey.send.value='Sending....';
 
    http.open('get', 'http://yourdomain.com/mailtest.php?emailaddress='+emailaddress+'&action=send');
    http.onreadystatechange = handleResponse;
    http.send(null);
}
 
function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
 
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
 
        }
    }
}
</script>
<div id="contactarea"><!--<form id="contactform" name="contactform">-->     <label>{INSERTANS:66911X1X4}</label><br />
<input type="hidden" value="{INSERTANS:66911X1X4}" name="emailaddress" id="emailaddress" />    <input type="button" id="submitbutton" onClick="sendemail();" name="send" value="Send Email" /> <!--</form>--></div>


in the code inserted the insertans to get the email id from a previous text question


then created a php file

[code type=php

$to = $_GET["emailaddress"]; //This is the email address you want to send the email to

if(!isset($_GET))

{

die("You are not authorised to access this page directly!"); //Just to stop people from visiting mailtest.php normally

}

$subject = "Test mail";

$message = '<html>

<head>

<title>Test Mail</title>

</head>

<body>

<p>This is a Test Mail!</p>

<table>

<p>Dear Customer,<br> <br>We thank you for being a part of.....</p>

</body>

</html>';

$from = "This email address is being protected from spambots. You need JavaScript enabled to view it.";



$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= "From:" . $from;



mail($to,$subject,$message,$headers); //a very simple send



echo 'contactarea|Thank you '.$to.', your email has been sent.'; //now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.

?>][/code]<?php

named the file mailtest.php and uploaded it somewhere on our site

thats it.. works like a charm for me. hope it will be of use to someone else.

Regards,
Samba
Last Edit: 5 years 9 months ago by Samba. Reason: Correction

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form