2017-02-05 26 views
1

サブスクリプションオプションに従って自動的に生成される添付ファイル付きのメールを送信しようとしています。しかし、メールが送信されるたびに(迷惑メールで)添付ファイルは送信されません。ここでこのトピックを検索しましたが、すべてのソリューションは「アップロード」フォルダに関連しています。ここで wp_mail()内の添付ファイルが自動生成されません

私のコードがある

..

require (ABSPATH . 'pdfcrowd.php'); 
        try 
        { 
         // create an API client instance 
         $client = new Pdfcrowd("apiname", "apikay"); 

         // convert a web page and store the generated PDF into a $pdf variable 
         $pdf = $client->convertFile(ABSPATH . 'invoice_html.php'); 

         // set HTTP response headers 
         header("Content-Type: application/pdf"); 
         header("Cache-Control: max-age=0"); 
         header("Accept-Ranges: none"); 
         header("Content-Disposition: attachment; filename=\"invoice.pdf\""); 

         //$to = $invoice_email; 
         $to = "[email protected]"; 
         $subject = "Invoice for your online package."; 
         $message = "Message Body Invoice for your online package. Invoice for your online package. Invoice for your online package"; 
         $headers = array('Content-Type: text/html; charset=UTF-8','From: My Site Name <[email protected]'); 
         $attachments = $pdf; 

         // send the generated PDF 
         //echo $attachments; 

         $wp_mail = wp_mail($to, $subject, $message, $headers, $attachments); 

        } 
        catch(PdfcrowdException $why) 
        { 
         echo "Pdfcrowd Error: " . $why; 
        } 

任意のヘルプ?

N.B:私はブラウザでPDFファイルを出力して保存することができたので、このpdfファイルをディレクトリに保存してから添付ファイルとして送信したいと思います。上記のコードで何が最善のものになるでしょうか?

おかげ

答えて

0

最後に、私は下に次の変更コードによって電子メールでPDFを送信することができていますが....

1.まず、私はちょうど

その後、アップロードフォルダに変換されたPDFファイルを保存します

2.添付ファイルのpdfを入手する

require (ABSPATH . 'pdfcrowd.php'); 
        try 
        { 
        // create an API client instance 
        $client = new Pdfcrowd("apiname", "apikay"); 

        // converted php file and store the generated PDF inside uploads 

        $fd = fopen(ABSPATH . 'wp-content/uploads/invoice.pdf', 'wb'); 
        $client->convertFile(ABSPATH . 'invoice_html.php', $fd); 
        fclose($fd); 

        // set HTTP response headers 
        header("Content-Type: application/pdf"); 
        header("Cache-Control: max-age=0"); 
        header("Accept-Ranges: none"); 
        //header("Content-Disposition: attachment; filename=\"invoice.pdf\""); 

        //$to = $invoice_email; 
        $to = "[email protected]"; 
        $subject = "Invoice for your online package."; 
        $message = "Message Body Invoice for your online package. Invoice for your online package. Invoice for your online package"; 
        $headers = array('Content-Type: text/html; charset=UTF-8','From: My Site Name <[email protected]'); 

    // take the file from the uploads folder 
        $attachments = array(ABSPATH . '/wp-content/uploads/invoice.pdf'); 


        // send the generated PDF 
        //echo $attachments; 

        $wp_mail = wp_mail($to, $subject, $message, $headers, $attachments); 

       } 
       catch(PdfcrowdException $why) 
       { 
        echo "Pdfcrowd Error: " . $why; 
       } 
関連する問題