Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:28:30+00:00 2026-06-07T02:28:30+00:00

I have written the following code to generate pdf and the pdf i generated

  • 0

I have written the following code to generate pdf and the pdf i generated fine and displayed,then in the second part i have written the code to generate mail automatically and send,but no response.. suggestions ?
Thanks in advance 🙂

  <?php

    require('fpdf.php');

    //Connect to your database
    $link = mysql_connect('xxxxx');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }

    //Create new pdf file
    $pdf=new FPDF();

    //Open file
    $pdf->Open();

    //Disable automatic page break
    $pdf->SetAutoPageBreak(true);

    //Add first page
    $pdf->AddPage();

    //set initial y axis position per page
    $y_axis_initial = 25;

    //print column titles for the actual page
    $pdf->SetFillColor(232, 232, 232);
    $pdf->SetFont('Arial', 'B', 12);
    $pdf->SetY($y_axis_initial);
    $pdf->SetX(5);
    /*$pdf->Cell(30, 6, 'CODE', 1, 0, 'L', 1);
    $pdf->Cell(30, 6, 'NAME', 1, 0, 'L', 1);
    $pdf->Cell(30, 6, 'PRICE', 1, 0, 'R', 1);*/

    $y_axis = $y_axis + $row_height;

    //Select the Products you want to show in your PDF file
    /*$result=mysql_query('select Code,Name,Price from Products ORDER BY Code',$link);*/

    mysql_select_db("brainoidultrafb", $link);
    $q = "SELECT qr_topics,start_of,differential_dia,things_not,investigations,risks FROM qr_table";
    $result = mysql_query ($q, $link);

    //initialize counter
    $i = 0;

    //Set maximum rows per page
    $max = 25;

    //Set Row Height
    $row_height = 80;
    $pdf->Cell(33, 6, '  ', 1, 0, 'L', 1);
    $pdf->Cell(33, 6, 'Starting off', 1, 0, 'L', 1);
    $pdf->Cell(33, 6, 'Differential diagnosis', 1, 0, 'L', 1);
    $pdf->Cell(33, 6, 'Not to miss', 1, 0, 'L', 1);
    $pdf->Cell(33, 6, 'Investigations', 1, 0, 'L', 1);
    $pdf->Cell(33, 6, 'Risks', 1, 0, 'L', 1);

    $y_axis =(35);

    while($row = mysql_fetch_array($result))
    {


        $cad = $row['qr_topics'];
        $pad = $row['start_of'];
        $nad = $row['differential_dia'];
        $vad = $row['things_not'];
        $sad = $row['investigations'];
        $tad = $row['risks'];

        $pdf->SetY($y_axis);
        $pdf->SetX(5);
        $pdf->Cell(33,80,$cad,1,0,'L',1);
        $pdf->Cell(33,80,$pad,1,0,'L',1);
        $pdf->Cell(33,80,$nad,1,0,'L',1);
        $pdf->Cell(33,80,$vad,1,0,'L',1);
        $pdf->Cell(33,80,$sad,1,0,'L',1);
        $pdf->Cell(33,80,$tad,1,0,'L',1);

        //Go to next row
        $y_axis = $y_axis + $row_height;
        $i = $i + 1;
    }

    mysql_close($link);

    //Send file
    //$pdf->Output();

    //email test

    // email stuff (change data below)
    $to = "aneeshyyyy@gmail.com"; 
    $from = "aneeshxxxx@gmail.com"; 
    $subject = "Patient Report"; 
    $message = "<p>Please see the attachment.</p>";

    // a random hash will be necessary to send mixed content
    $separator = md5(time());

    // carriage return type (we use a PHP end of line constant)
    $eol = PHP_EOL;

    // attachment name
    $filename = "test.pdf";

    // encode data (puts attachment in proper format)
    $pdfdoc = $pdf->Output("", "S");
    $attachment = chunk_split(base64_encode($pdfdoc));

    // main header
    $headers  = "From: ".$from.$eol;
    $headers .= "MIME-Version: 1.0".$eol; 
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

    // no more headers after this, we start the body! //

    $body = "--".$separator.$eol;
    $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
    $body .= "This is a MIME encoded message.".$eol;

    // message
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
    $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
    $body .= $message.$eol;

    // attachment
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
    $body .= "Content-Transfer-Encoding: base64".$eol;
    $body .= "Content-Disposition: attachment".$eol.$eol;
    $body .= $attachment.$eol;
    $body .= "--".$separator."--";

    // send message
    mail($to, $subject, $body, $headers);


    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:28:31+00:00Added an answer on June 7, 2026 at 2:28 am

    Found the solution and its working very fine,change the above code as follows

      // email stuff (change data below)
    $to = "saxxxx@gmail.com"; 
    $from = "aneexxxxx@gmail.com"; 
    $subject = "Patient detials with pdf attachment"; 
    $message = "<p>Please see the attachment.</p>";
    
    // a random hash will be necessary to send mixed content
    $separator = md5(time());
    
    // carriage return type (we use a PHP end of line constant)
    $eol = PHP_EOL;
    
    // attachment name
    $filename = "patientdetials.pdf";
    
    // encode data (puts attachment in proper format)
    $pdfdoc = $pdf->Output("", "S");
    $attachment = chunk_split(base64_encode($pdfdoc));
    
    // main header (multipart mandatory)
    $headers = "From: ".$from.$eol;
    $headers .= "MIME-Version: 1.0".$eol;
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
    
    //NOTICE I changed $headers to $body!!
    
    $body .= "Content-Transfer-Encoding: 7bit".$eol;
    $body .= "This is a MIME encoded message.".$eol; //had one more .$eol
    
    // message
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
    $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
    $body .= $message.$eol; //had one more .$eol
    
    // attachment
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
    $body .= "Content-Transfer-Encoding: base64".$eol;
    $body .= "Content-Disposition: attachment".$eol.$eol;
    $body .= $attachment.$eol;
    $body .= "--".$separator."--";
    
    // send message NOTICE I replaced "" with $body
    mail($to, $subject, $body, $headers);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code in my Rails app to generate XML. I
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in
i have written the following code class Program { static void Main(string[] args) {
I have written the following code, CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); report.Load(@C:\Users\XXX\Desktop\Backup1\Project\ReportsFolder\ReportSalesInvoice.rpt); Report works
I have written a following code to get just the file name without extension
I have written the following code choice /m Do you want to add another
I have written the following code. But it is removing only &nbsp; not <br>
i have written the following code: As you can see there is a for
I have written the following code in Perl. I want to iterate through a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.