Email PDF Attachment with PHP Using FPDF


#1

I'm creating a pdf file using fpdf and trying top send it as an attachment using mail() in php.

Below is my code

    $pdf=new FPDF();
    $pdf->AddPage();
   
    $pdf->SetFont('Arial','B',14);
    $txt = "Legal Document of Mr." .$result[0]['first_name'];
    $pdf->Cell(180,0,$txt,0,1,'C');
    $pdf->Line(5,20,200,20);
    $pdf->SetFont('Arial','',12);
    $content = "This is the AGREEMENT to purchase made by ".$result[0]['first_name'] ." from XYZ on day XX/XX/XXXX,";
    $pdf->Cell(5,30,$content,0,0,'');
    $content = "is located at " . $result[0]['location']."and his dob is ".$result[0]['dob']." will be owner of the plot";
    $pdf->Cell(0,45,$content,0,0,'');
  
    $attachment   = $pdf->Output("doc.php", "S");


     // carriage return type (we use a PHP end of line constant)
     $eol = PHP_EOL;
	
     $name1 = "Document";
     $to = $result[0]['cust_email'];

         $messageca = "<html>
		  <div style='padding:0 10px 10px 10px; font-size:12px;'>
			Hello " . $result[0]['first_name'] . ",
			<br/><br/>
			Please find below attached demand note.
			<br/><br/>				
			Thank You,
			<hr/>
			</div>
			</body>
			</html>";

     // message
     $body = $messageca.$eol;


     // attachment
     $body .= $attachment.$eol;



      $subject = "$name1| XYZ";
      $message = 'FROM: ' . $result[0]['first_name'] . ' Email: ' . $to . 'Message: ' . $messageca;
   
	  $headers = "MIME-Version: 1.0" . "\r\n";
      $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
      $headers .= "From: 'XYZ'<XYZ@gmail.com>\nReply-To:XYZ@gmail.com";

I'm recieving the mail, but with encoded attachment like below...

  Hello XYZ, 

  Please find below attached demand note. 

  Thank You,


 %PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream xœUÐÁN„0 …áý> endobj 5 0 obj <> stream xœ]RËnƒ0 ¼ó >¦‡ L ‚%„DI 8ô¡Ò~ %E* ràï»»vÒªHXã±gvVk?/ ¥î á¿™±©` ]¯[ óx5 ˆ3\zíÉP´}³¸ ¯ÍPOž âj JÝ ^’øïx6/f ›¬ Ïðàù¯¦ Óë‹Ø|æ î«ë4}à z —¦¢… }žëé¥ @ø,Û–-ž÷˺EÍï u ò^Ú,ÍØÂà ! J"V! 2&bGÄ£%r"H¢¬Dî È\}2EL1n ¥º h¾jƒå –eä »" a* H¬‹ØÕ: ÞÛd á˜î„9cÅüŽ[ÈX 1~²¼"œ3¿gÏ ãÑò;Oâ•õ> endobj 7 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 6 0 R /F2 7 0 R >> /XObject << >> >> endobj 8 0 obj << /Producer (FPDF 1.81) /CreationDate (D:20180213093154) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 10 0000000000 65535 f 0000000413 00000 n 0000001165 00000 n 0000000009 00000 n 0000000087 00000 n 0000000500 00000 n 0000000934 00000 n 0000001052 00000 n 0000001279 00000 n 0000001355 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 1404 %%EOF

what is the mistake..??


#3

What else did you expect from concatenating a text with a file? What you produce is not a valid multipart email

or you just use a wrapper like PHPMailer...


closed #4

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.