在wp_mail()中自动生成附件文件丢失 [英] auto generate attachment file missing in wp_mail()

查看:104
本文介绍了在wp_mail()中自动生成附件文件丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送带有根据订阅选项自动生成的附件的邮件。但每次邮件发送(在垃圾邮件中),但附件不是。我在这里搜索了这个主题,但所有的解决方案都与'uploads'文件夹相关。

I am trying to send a mail with an attachment which is generating automatically according to the subscription option. But every time the mail is being sent (in Spam) but the attachment is not. I searched to this topic here but all the solutions are related to the 'uploads' folder.

这是我的代码..

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 = "moyen@gmail.com";
                        $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 <uddin@gmail.com');
                        $attachments = $pdf;

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

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

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

任何帮助?

注意:由于我设法在浏览器中输出pdf文件以保存,但我想将此pdf文件保存在目录中,然后作为附件发送。以上代码将是最好的?

N.B:Since I managed to output the pdf file in the browser to save but I would like to save this pdf file in a directory and then will send as attachment. What will be the best with this code above ?

谢谢

推荐答案

最后,我可以通过下面的修改代码发送pdf的邮件。

Finally I am able to send the pdf in email by the following modification code below....

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 = "moyen@gmail.com";
                    $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 <uddin@gmail.com');

     // 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;
                }

这篇关于在wp_mail()中自动生成附件文件丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆