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__)
Code:
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!';