1

How can I reference the below div using the ID as a PHP variable is the same script?

<?php

    $variableIDqamaildiv -> How should I assign it to the DIV with the ID below

?>

<div contentEditable="true" class="qamaildiv" id="qamaildiv">

  Dear <?php echo $ccname; ?>,<br><br>

  Regarding QA of Canvas ID: <?php echo $courseTerm;?><br><br>

  <p>Students will now be given access to the Canvas course shell seven days prior to the class start date.</p>

  <p>If you have any questions, please contact <a href="mailto:abc@abc.com?Subject=QA%20Query%20regarding%20<?php echo $_POST['code_term']?>">abc@abc.com</a>.</p>

  Kind Regards,<br><br>
  INSERT SIGNATURE

</div>

2 Answers2

0

Below is a working example. Although you would need to refine it.

<script type="text/javascript">

function sendEmail(){

elm = document.getElementById('send_email');
elm.href = "mailto:abc@abc.com?subject=subject of the email&body="+ document.getElementById('qamaildiv').innerHTML;
}
</script>
</head>

<body>

<a href="#" onclick="return sendEmail();" id="send_email">Send Email</a>
<div contentEditable="true" class="qamaildiv" id="qamaildiv" >

  Dear <?php echo $ccname; ?>,<br><br>

  Regarding QA of Canvas ID: <?php echo $courseTerm;?><br><br>

  <p>Students will now be given access to the Canvas course shell seven days prior to the class start date.</p>

  <p>If you have any questions, please contact <a href="mailto:abc@abc.com?Subject=QA%20Query%20regarding%20<?php echo $_POST['code_term']?>">abc@abc.com</a>.</p>

  Kind Regards,<br><br>
  INSERT SIGNATURE

</div>
</body>
</html>
SynapseIndia
  • 450
  • 2
  • 10
  • Hi @synapseIndia. Your code is working, however, the entire body is not getting copied into the email. Does your code limit the number of characters copied into the body of the email? – user3535656 Jul 17 '18 at 01:34
  • I have not put any limit on number of characters may be due to quotes the string breaks. – SynapseIndia Jul 17 '18 at 06:10
0

I used the following solution to send the email. Thank you, everyone, for lending your helping hand. I need help with how I can reference I want to reference the <DIV> with ID=qamaildivas a PHP variable at the top of this script. How can I represent a block of HTML code as a PHP variable as explained above?

Thank you in advance.

<?php

// My initial PHP code. Removing it here because of privacy concerns. :)
// Then added the PHP mailer

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
$mail;
try {
    //Server settings
    $mail->SMTPDebug = 1;                              // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'HOSTNAME';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'USER EMAIL ID';          // SMTP username
    $mail->Password = 'PASSWORD';                           // SMTP password
    $mail->SMTPSecure = 'tls';          // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('sendFROMemailID', 'Heading');
    $mail->addAddress('sendTOEMAILID','NAME');     // Add a recipient
//    $mail->addAddress('ellen@example.com');               // Name is optional
//    $mail->addReplyTo('info@example.com', 'Information');
//    $mail->addCC('cc@example.com');
//    $mail->addBCC('bcc@example.com');

    //Attachments (if any)
      $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
      $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}


?>


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Congratulations!</title>

</head>
<body>

<div>
<form method="post" action="publishqa_true.php">
<div contentEditable="true" class="qamaildiv" id="qamaildiv">

Dear ,<br><br>

Regarding QA of Canvas ID: <?php echo $Term;?><br><br>

<p>We are very pleased to say that your above course has satisfied all blah Success and therefore is ready to teach out of Canvas.</p>

<p>Students will now be given access to the blah course shell seven days prior to the class start date.</p>

<p>We would like to sincerely thank you for all of your efforts in embracing blah and helping to improve the blah experience. We provided our personal notes for each of the blah below:</p>


Kind Regards,<br><br>
INSERT SIGNATURE<br>

</div><br>


<input class="ch-button" type="submit" name="submit" value="Send Email">

</form>
</div>


</body>
</html>


// Prewritten footer file loading at the bottom of this file
<?php require_once("../private/layout/footer.php"); ?>