无法通过phpmailer AddAttachment发送正确的pdf文件

时间:2016-09-30 13:37:55

标签: php pdf add phpmailer attachment

    private function mailToClient($file, $customer, $trans_id = "")
{
    if(!$customer["email"]) return;
    $mail = &$this->getMailObject();
    $country = $_SESSION[PROJECT]["user"]["details"]["country"];
    $lang = getLanguage();

    if( empty($trans_id))
    {
        //get header
        $set = getContentByCode("client_email_header");
        if(!$set->EOF)
            $msg_html = $set->fields["content_$lang"];
    }
    else 
    {
        //get header
        $set = getContentByCode("client_email_with_card_header");
        if(!$set->EOF)
            $msg_html = $set->fields["content_$lang"];
    }
    if( $country != "Schweiz" && !empty($trans_id))
    {
        //get header
        $set = getContentByCode("client_email_nonswiss_card");
        if(!$set->EOF)
            $msg_html = $set->fields["content_$lang"];
    }
    $msg_html = $this->replacePlaceHolders($msg_html, $customer);
    $msg_plain = strip_tags($msg_html);

    //get footer
    $set = getContentByCode("client_email_footer");
    if(!$set->EOF)
        $msg_html2 = $set->fields["content_$lang"];

    $msg_html2 = $this->replacePlaceHolders($msg_html2, $customer);
    $msg_plain2 = strip_tags($msg_html2);

    //get order
    $order = file_get_contents($file);

    $mail->Subject = (EMAIL_SUBJECT_PREFIX ? EMAIL_SUBJECT_PREFIX." " : "")."Order from TERRA KERAMIK";
    $mail->Body = $msg_html."<br />".$order."<br />".$msg_html2;
    $mail->AltBody = $msg_plain.$msg_plain2;            
    //$mail->AddAttachment($file, date("d.m.Y H_i")." order.xls");
    $mail->AddAttachment($file, date("d.m.Y H_i")." ".mn_transliterate($customer["name"]." ".$customer["surname"].".pdf", $encoding = 'base64', $type = 'application/pdf'));
    $mail->AddAddress($customer["email"], $customer["name"]." ".$customer["surname"]);
    $mail->Send();

我知道有类似的问题,但是他们提供的解决方案并没有帮助。试试我的运气。

所以,我已经获得了这个代码,可以向客户发送电子邮件并添加附件。附件本身是一个html表。它也会添加到电子邮件中,看起来像this

当我收到电子邮件时,附件已存在,但已损坏或损坏。其他解决方案建议添加&#34; $encoding = 'base64', $type = 'application/pdf'&#34;以及文件路径和名称。

这根本不会改变情况。同时这段代码,目前已注释为 //$mail->AddAttachment($file, date("d.m.Y H_i")." order.xls");工作得非常好,我收到一个包含信息的excel文件。

有什么想法吗?

0 个答案:

没有答案