Retrieving an email template for the current survey

More
1 week 1 day ago - 1 week 1 day ago #203357 by Indispirit
Hey all, how would I go about retrieving an email template from the survey a user is completing as an html file?


My current set-up is as follows:
* Token based surveys where one person at the client organisation shares a single token with multiple users
* User completes the survey and provides their email address in order for us to email them the results as a pdf
* All the work for this is done in end text and a php file that it calls up to invoke php mailer
* The php file formulates the message body by loading up hello.html, a file I've created

All this works successfully, but I think it would be better if I could save the hello html text in the survey in the registration template and call it from there. That would mean users could make changes to the text using LS rather than editing a seperate html file.

What code would I need to do this? Current code, the line to change would be: $mail->msgHTML(file_get_contents('hello.html'), __DIR__)


 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
 
require '../../application/third_party/phpmailer/src/Exception.php';
require '../../application/third_party/phpmailer/src/PHPMailer.php';
require '../../application/third_party/phpmailer/src/SMTP.php';
 
if ( 0 < $_FILES["data"]["error"] ) {
        echo 'Error: ' . $_FILES["data"]["error"] . '<br>';
    }
    else {
        $a = get_defined_vars();unset($a['GLOBALS'], $a['_ENV'], $a['_SERVER']);print_r($a);
        // This is in the PHP file and sends a Javascript alert to the client
        $message = "uploaded file!";
        $uid = sha1($_POST["drivemail"]);
        $fnamedir = "uploads/drive_".$uid.".pdf";
        $fname = "drive_".$uid.".pdf";
        echo "<script type='text/javascript'>alert('$message');</script>";
        move_uploaded_file($_FILES["data"]["tmp_name"],  $fnamedir);
    }
 
//Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "some@somedomain.com";
$mail->Password = "something";
//Set who the message is to be sent from
$mail->setFrom('some@somedomain.com', 'some');
//Set an alternative reply-to address
$mail->addReplyTo('some@somedomain.com', 'some');
//Set who the message is to be sent to
$mail->addAddress($_POST["drivemail"], some');
//Set the subject line
$mail->Subject = 'Your DRIVE Survey Results';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('hello.html'), __DIR__);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment($fnamedir, $fname);
 
//send the message, check for errors
if (!$mail->send()) {
    echo 'Mailer Error: '. $mail->ErrorInfo;
} else {
    unlink($fnamedir);
    echo 'Message sent!';
Last edit: 1 week 1 day ago by Indispirit.

Please Log in to join the conversation.

More
1 week 22 hours ago #203370 by DenisChenu
I put a lot of sample code : gitlab.com/SondagesPro/ExportAndStats/pd...r/pdfReport.php#L772

I never create code for other on forum … here : you put whole code, your question are unclear …

And seems not related to LimeSurvey …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.
The following user(s) said Thank You: Indispirit

Please Log in to join the conversation.

More
1 week 22 hours ago #203374 by Indispirit
Thanks for the reply Denis, but I don't understand?

"And seems not related to LimeSurvey … "


For the current Lime Survey the user is completing I'm trying to retrieve the contents of registration email template held in the Lime Survey database???

Please Log in to join the conversation.

More
1 week 21 hours ago #203379 by Joffm

User completes the survey and provides their email address in order for us to email them the results as a pdf

That would mean users could make changes to the text using LS rather than editing a seperate html file.


This is the same user?
He will get his results, but is allowed to change?


Anyway:
You know that the email templates are stored in "lime_surveys_languagesettings".
You should be able to load them from your php program and use them.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 week 21 hours ago #203383 by DenisChenu
OK,

You don't use LimeSurvey plugin or API …

Then :

You know that the email templates are stored in "lime_surveys_languagesettings".
You should be able to load them from your php program and use them.

+1

Create a SQL request is not a LimeSurvey question …
Be clerar : ask something like "Where is the content of registration email template held in the Lime Survey database" don't put whole PHP code …

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now