0

我已经使用 tcpdf 函数创建了一个 PDF,然后我想将它作为附件发送到邮件中。我在 PDF 创建结束时使用了以下编码。但它在某些服务器上工作,但在其他一些服务器上不工作

$from = "manikandan@niral.us";
        $subject = "test";
        $message = $_REQUEST['msg'];


        // 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;
         // $eol = "\r\n";
        // attachment name
        $filename = "Yourinvices.pdf";

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

        // encode data (multipart mandatory)
        $headers = "From: ".$from.$eol;
        $headers .= "MIME-Version: 1.0".$eol;
        $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
        $headers .= "Content-Transfer-Enconding: 7bit".$eol;
        $headers .= "This is a MIME encoded message.".$eol.$eol;

        // message
        $headers .= "--".$separator.$eol;
        $headers .= "Content-Type: text/html; charsrt=\"iso-8859-1\"".$eol;
        $headers .= $message.$eol.$eol;

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

        // send message
       if(@mail($to, $subject, $message, $headers))
       {

         Redirect("../../patient_invoicelist.php?msg=1");   
      }

       else Redirect("../../patient_invoicelist.php?msg=2");   
4

1 回答 1

0

用于PHPMailer发送Emails with Attachments。使用这个库发送带有附件的电子邮件将非常容易。从此链接

下载库。PHPMailer您还将找到使用此类的示例。

http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/

$mail->SetFrom('noreply@test.com', 'test');
$mail->Subject    = $subject;
$mail->AddAttachment($Pdf_path_here);
$mail->MsgHTML($body);
$mail->AddAddress($to, "");

if(!$mail->Send()) 
{
   echo "sent";
} 
else 
{
   echo "error";
}
于 2013-03-05T08:21:50.513 回答