Bugs in sending documents as email. Seems to land in the spam filter due to bad text...
[fa-stable.git] / reporting / includes / pdf_report.inc
index 81fda39f8ccdf2c744b1566254011e064a3ac19e..8d9bef0f86f1df55091a67660d9a99e06e75b27a 100644 (file)
@@ -406,7 +406,10 @@ class FrontReport extends Cpdf
                        }
                        // do not use standard filenames or your sensitive company data 
                        // are world readable
-                       $fname = $dir.'/'.uniqid('').'.pdf';
+                       if ($email == 1)
+                               $fname = $dir.'/'.$this->filename;
+                       else    
+                               $fname = $dir.'/'.uniqid('').'.pdf';
                        $this->Output($fname, 'F');
                        if ($email == 1)
                        {
@@ -421,8 +424,8 @@ class FrontReport extends Cpdf
                                }
                                require_once($path_to_root . "/reporting/includes/class.mail.inc");
                        $mail = new email($this->company['coy_name'], $this->company['email']);
-                       $from = $this->company['coy_name'] . " <" . $this->company['email'] . ">";
-                               if (!isset($myrow['email']) || $myrow['email'] == '') $myrow['email'] = $myrow['contact_email'];
+                               if (!isset($myrow['email']) || $myrow['email'] == '') 
+                                       $myrow['email'] = $myrow['contact_email'];
                        $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">";
                        $msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject .
                                "\n\n";
@@ -445,25 +448,12 @@ class FrontReport extends Cpdf
                        $mail->text($msg . $sender);
                        $mail->attachment($fname);
                        $ret = $mail->send();
-                       if (1 == 1) // just for fun and for debugging purposes!!
-                       {
-                               $from = str_replace("<", "(", $from);
-                               $from = str_replace(">", ")", $from);
-                               $to = str_replace("<", "(", $to);
-                               $to = str_replace(">", ")", $to);
-                               $msg2 = "<br>From: " . $from;
-                               $msg2 .= "<br>To: " . $to;
-                               $msg2 .= "<br>Subject: " . $subject;
-                               $msg2 .= "<br>Msg: " . nl2br($msg);
-                               $msg2 .= nl2br($sender) . "<br>";
-                               $msg2 .= "<br>Filepath: " . $fname . "<br>Filename: " . $this->filename . "<br>";
-                       }
-                       if (!isset($myrow['reference'])) $myrow['reference'] = '';
                                if (!$ret)
                                        display_error(_("Sending document by email failed"));
                                else
                                        display_notification($this->title . " " . $myrow['reference'] . " " 
                                                . _("has been sent by email."));
+                               unlink($fname);         
                        }
                        else
                        {