PHP отправить письмо с вложением в формате PDF

Я создаю PDF, используяFPDF , PDF генерирует отлично, а также PDF доступен по электронной почте. Но я хочу также отправить сообщение для тела. Я пытался с сообщением тела. Пример текстового сообщенияThis is text message from shohag Но доступно только вложение в формате PDF, а тело пусто. Вот мой код

function send_pdf_to_user(){
    if($_REQUEST['action'] == 'pdf_invoice' ){
        require('html2pdf.php');
        $pdf=new PDF_HTML();
        $pdf->SetFont('Arial','',11);
        $pdf->AddPage();

        $text = get_html_message($_REQUEST['eventid'], $_REQUEST['userid']);
        if(ini_get('magic_quotes_gpc')=='1')
        $text=stripslashes($text);
        $pdf->WriteHTML($text);

        //documentation for Output method here: http://www.fpdf.org/en/doc/output.htm
        $attach_pdf_multipart = chunk_split( base64_encode( $pdf->Output( '', 'S' ) ) );


        //define the receiver of the email 
        $to = '[email protected]';

        //define the subject of the email 
        $subject = 'Test Invoice'; 
        //create a boundary string. It must be unique 
        //so we use the MD5 algorithm to generate a random hash 
        $random_hash = md5(date('r', time())); 
        //define the headers we want passed. Note that they are separated with \r\n 
        $headers = "From: [email protected]\r\nReply-To: [email protected]"; 
        //add boundary string and mime type specification 
        $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";       



        $msg .= "Content-Type: application/octet-stream; name=\"attachment.pdf\"\r\n";
        $msg .= "Content-Transfer-Encoding: base64\r\n";
        $msg .= "Content-Disposition: attachment\r\n";
        $msg .= $attach_pdf_multipart . "\r\n";

        $msg .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
        $msg .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        $msg .= "<p>This is text message from shohag</p>\r\n\r\n";  

        global $message;
        $message = '';
        $mail_sent = @mail( $to, $subject, $msg, $headers );
        //@mail( $to1, $subject, $msg, $headers );
        if(!empty($mail_sent)):
            $message = "Invoice sent succuessfully";
        else:
            $message = "Error occured. Please try again.";
        endif;
    }
}

Пожалуйста, проверьте мой код и дайте мне знать больше возможностей. Заранее спасибо.

Ответы на вопрос(4)

Ваш ответ на вопрос