生成并发送带有邮件的pdf文件

I want to generate and send pdf file in mail. When I receive mail, the content inside pdf file is not correct. Here is my code:

                $txt = 'hello';
                $dompdf = $this->get('slik_dompdf');
                $dompdf->getpdf($txt);
                $dompdf->stream('karan.pdf');
                $pdfoutput = $dompdf->output();
                $a = chunk_split(base64_encode($pdfoutput));
                // echo"<pre>";print_r($pdf) ;die;
                $filename = $pdfoutput;

                $email = 'abhinandank@ocodewire.com';
                $date = date("Y/m/d.");
                $headers = "MIME-Version: 1.0" . "
";
                $headers .= "Content-type:text/html;charset=UTF-8" . "
";
                $headers .= 'From: <support@rdrp.com>' . "
";
                $headers .= "Content-Disposition: attachment; filename=\"" . $filename . "\"

";
                $to = $email;
                $subject = "Registrar Admin Password Reset";
                $txt=  'hello your information is in attachment';

                mail($to,$subject,$txt,$headers);

Please Help.

Try this...!!

$content="<html>html content here</html>"  ; 

$html2pdf = Yii::app()->ePdf->HTML2PDF();

$html2pdf->WriteHTML($content);
$to = "dheerajchouhan85@gmail.com";
$from = "no-reply@email.com";
$subject = "Thank you for your Contribution";
$message = "<p>Your Message</p>";

$separator = md5(time());
$eol = PHP_EOL;
$filename = "example.pdf";
$pdfdoc = $html2pdf->Output('', 'S');
$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: " . $from . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol . $eol;

$body .= "Content-Transfer-Encoding: 7bit" . $eol;
$body .= "This is a MIME encoded message." . $eol; 
$body .= "--" . $separator . $eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
$body .= $message . $eol;
$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 . "--";
mail($to, $subject, $body, $headers);

I suggest you to use PHPMailer for sending email because it's very simple to use and mpdf library for creating PDFs (html2pdf conversion + utf-8 support). I have created application that sends dinamically created PDFs via email and it works perfectly.

PHPMailer: https://github.com/PHPMailer/PHPMailer

mpdf: http://www.mpdf1.com/mpdf/index.php