mPDF自动生成的PDF邮件发送空白电子邮件 [英] mPDF Auto Generated PDF Mailer sends blank Email

查看:221
本文介绍了mPDF自动生成的PDF邮件发送空白电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mPDF类,我可以成功地使用以下代码生成一封电子邮件。但是,我的电子邮件是空白的。我假设,但不知道这是否与我的标题有关。我很难说,因为我收到我的电子邮件,但不能打开它产生的pdf。

I am using mPDF class and am successfully able to generate an email with the following code. However, my email comes out blank. I am assuming but am not sure if this has something to do with my headers. It's hard for me to tell because I am getting my emails but am not able open the pdf it generates.

         include("./mpdf.php");

         $mpdf->debug = true;

         $html2 = '
              <div style="margin-left:3%;">Attach additional photos: 
              <input type="file" name="file" id="file" /></div><hr />';

         echo $html2;



         if ( isset( $_POST['submit'] ) ) {
         $file_path = "webform.php";
         $file_path_type = "application/pdf";
              $mpdf=new mPDF('iso-8859-2');
              $mpdf->WriteHTML($html);

         $file_path_name = "eval.pdf"; 
         $headers .= 'Content-type: text/html; charset=utf-8' . "\n"; 
         $from = "info@myemail.com";
         $to = $_POST['email'];
         $ccto = $_POST['youremail'];
         $subject = "New Form Submitted"; 
         $message = "*** This is an automatically generated email, 
                   please do not reply *** Someone in your association 
                   has completed a survey.

         $headers = "From: ".$from;
         $headers.= "cc: " . $ccto . " <" . $ccto . ">" . "\n" ;
         $file = fopen($file_path,'rb');
         $data = fread($file,$file_path);
         fclose($file); 

         $rand = md5(time());
         $mime_boundary = "==Multipart_Boundary_x{$rand}x"; 

         $headers .= "\nMIME-Version: 1.0\n" .
         "Content-Type: multipart/mixed;\n" .
         " boundary=\"{$mime_boundary}\""; 

         $message .= "This is a multi-part message in MIME format.\n\n" .
         "--{$mime_boundary}\n" .
         "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
         "Content-Transfer-Encoding: 7bit\n\n" .
         $message .= "\n\n"; 


         $data = chunk_split(base64_encode($data)); 

        $message .= "--{$mime_boundary}\n" .
          "Content-Type: {$file_path_type};\n" .
          " name=\"{$file_path_name}\"\n" .
          "Content-Disposition: attachment;\n" .
          " filename=\"{$file_path_name}\"\n" .
          "Content-Transfer-Encoding: base64\n" .
        $data .= "\n\n" .
          "--{$mime_boundary}--\n";  

        if(@mail($to, $subject, $message, $headers)) {
        echo '<script language="javascript">';
        echo 'alert("Document sent successfully!")';
        echo '</script>';
        echo "Sent!";

        } else {
        echo 'Failed';
        }
        }
        exit;

PHP邮件和mpdf用户任何帮助将不胜感激。

PHP mail and mpdf users any help would be appreciated.

推荐答案

你正在学习困难 - 不要调用 mail()你自己,因为你会做错了;构建和发送电子邮件是非常复杂的,充满了陷阱,正如你所发现的那样。使用图书馆,无论是 PHPMailer ,SwiftMailer Zend_Mail等,它将为您节省大量的麻烦。您还需要分别检查您的两个操作 - 首先创建一个PDF,将其写入文件并确保其正常工作;然后写一些发送消息的代码,并检查是否有效;然后让它发送PDF。否则,如果你发现它不工作,你将无法知道哪一部分是坏的。

You're learning the hard way - Don't call mail() yourself because you will do it wrong; constructing and sending email messages is horribly complicated and full of pitfalls, as you're finding. Use a library, whether PHPMailer, SwiftMailer Zend_Mail etc, to do it and it will save you a great deal of hassle. You also need to check your two operations separately - first create a PDF, write it to a file and make sure it works correctly; Then write some code that sends a message and check that works; Then get it to send the PDF. Otherwise if you find it's not working, you won't be able to tell which part is broken.

这篇关于mPDF自动生成的PDF邮件发送空白电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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