Retrieving an email template for the current survey

More
1 year 5 months ago - 1 year 5 months 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 year 5 months ago by Indispirit.
The topic has been locked.
More
1 year 5 months 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
The topic has been locked.
More
1 year 5 months 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???
The topic has been locked.
More
1 year 5 months 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
The following user(s) said Thank You: Indispirit
The topic has been locked.
More
1 year 5 months 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.
The following user(s) said Thank You: Indispirit
The topic has been locked.
More
1 year 5 months ago #204062 by Indispirit
Thanks both for your responses.

Denis, after reviewing your sample code, would it be possible for me to use the sendmailmessage function to replace most of my code in a more secure and robust way?

Thanks for bearing with me as I'm learning as I'm going with some very out of date CS knowledge.

Presumable I would need:

use application/helpers/common-helper/sendmailmessage;
require '../application/helpers/common-helper.php';

And maybe getSurveyInfo and getConfig too?

Then I'd need to populate the parameters of SendEmailMessage which seems to rely on Yii framework extensions

- ($aMessage = getSurveyInfo($this->_iSurveyId, Yii::app()->language) and \Template::model()->getInstance(null, $this->_iSurveyId)

- $aMessage,= can do

- $sRecipient, = can do

- other parameters - sender email name and address from "{$oSurvey->admin} <{$oSurvey->adminemail}>", Yii::app()->getConfig("sitename"), true, getBounceEmail($this->_iSurveyId), $aAttachments)) {

Apologies, ordinarily would be trying to find someone to pay to do this for me but it's a brave new world...
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now