I have php page, 2.php, which collects the data and dispalys it from previous page , 1.php.

In 2.php, I also have html and javaScript, which contains a button, and cerresponding onclick script, which opens the OUTLOOk to send the E-mail with given sendername and subject.

But for body part of the mail, I want to fetch the details displayed in 2.php and print it using JavScript.

//My <script>

<script type = "text/javascript" src = "script/mail.js"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnSendEmail').click(function (event) {
        var email = 'senderemail@email.com';
        var subject = 'Hello!!';
        var emailBody = 'need to fetch the data and print it here';
        window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;

In 2.php you should have details enclosed within an html eement (such as div) with an ID so that you can access it using jquery text() or html() or similar method.

<div id="my-content">
This is the body of the email.

var emailBody = $("#my-content").text();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.