From bea28752e406cf6e00ac0ae08b30c96179a7b479 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sat, 13 Jun 2009 14:45:25 +0000 Subject: [PATCH] Improved email sending of documents. With help of Tom Moulton --- CHANGELOG.txt | 9 +++++++-- reporting/includes/class.mail.inc | 21 ++++++++++++++++++++- reporting/includes/pdf_report.inc | 5 +++-- reporting/rep109.php | 2 +- reporting/rep209.php | 3 ++- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 33e87ed7..17d44a9d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,10 +19,15 @@ Legend: ! -> Note $ -> Affected files -13-Jun-2009 Joe Hunt +13-Jun-2009 Joe Hunt/Pete/Tom Moulton ! Changed next reference method to also include partly alpha characters in front, fi. WA036 increments to WA037 $ /includes/references.inc - +! Improved email sending of documents. With help of Tom Moulton +$ /reporting/rep109.php + /reporting/rep209.php + /reporting/includes/class.mail.inc + /reporting/includes/pdf.report.inc + 12-Jun-2009 Joe Hunt ! Code clean-up $ /gl/includes/db/gl_db_trans.inc diff --git a/reporting/includes/class.mail.inc b/reporting/includes/class.mail.inc index 3cc1d1d2..7e6be6f9 100644 --- a/reporting/includes/class.mail.inc +++ b/reporting/includes/class.mail.inc @@ -67,6 +67,25 @@ class email $this->body .= "\n".$html."\n\n"; } + function mime_type($filename) + { + $file = basename($filename, '.zip'); + if ($filename == $file . '.zip') return 'application/x-zip-compressed'; + $file = basename($filename, '.pdf'); + if ($filename == $file . '.pdf') return 'application/pdf'; + $file = basename($filename, '.csv'); + if ($filename == $file . '.csv') return 'application/vnd.ms-excel'; + $file = basename($filename, '.tar'); + if ($filename == $file . '.tar') return 'application/x-tar'; + $file = basename($filename, '.tar.gz'); + if ($filename == $file . '.tar.gz') return 'application/x-tar-gz'; + $file = basename($filename, '.tgz'); + if ($filename == $file . '.tgz') return 'application/x-tar-gz'; + $file = basename($filename, '.gz'); + if ($filename == $file . '.gz') return 'application/x-gzip'; + return 'application/unknown'; + } + function send() { // CC Empfänger hinzufügen @@ -105,7 +124,7 @@ class email { $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i])); $this->header .= "--".$this->boundary."\n"; - $this->header .= "Content-Type: application/x-zip-compressed; name=".basename($this->attachment[$i])."\n"; + $this->header .= "Content-Type: " .$this->mime_type(basename($this->attachment[$i])). "; name=".basename($this->attachment[$i])."\n"; $this->header .= "Content-Transfer-Encoding: base64\n"; $this->header .= "Content-Disposition: attachment; filename=".basename($this->attachment[$i])."\n\n"; $this->header .= chunk_split(base64_encode($file))."\n"; diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index dd451859..1a0f7174 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -422,8 +422,9 @@ 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 ($myrow['email'] == '') $myrow['email'] = $myrow['contact_email']; $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">"; - $msg = $doc_Dear_Sirs . ",\n\n" . $doc_AttachedFile . " " . $subject . + $msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject . "\n\n"; if ($myrow['dimension_id'] > 0 && $doctype == 10) // helper for payment links { @@ -438,7 +439,7 @@ class FrontReport extends Cpdf } } $msg .= $doc_Kindest_regards . "\n\n"; - $sender = $this->user . "\n" . $this->company['coy_name']; + $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone']; $mail->to($to); $mail->subject($subject); $mail->text($msg . $sender); diff --git a/reporting/rep109.php b/reporting/rep109.php index c5faf769..7c57da3f 100644 --- a/reporting/rep109.php +++ b/reporting/rep109.php @@ -163,7 +163,7 @@ function print_sales_orders() $myrow['contact_email'] = $branch['email']; $myrow['DebtorName'] = $branch['br_name']; } - $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow); + $rep->End($email, $doc_Invoice_no . " " . $i, $myrow); } } if ($email == 0) diff --git a/reporting/rep209.php b/reporting/rep209.php index f369a0e7..046738d0 100644 --- a/reporting/rep209.php +++ b/reporting/rep209.php @@ -31,7 +31,7 @@ function get_po($order_no) { $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.supp_account_no, ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.payment_terms, ".TB_PREF."locations.location_name, - ".TB_PREF."suppliers.email, ".TB_PREF."suppliers.address + ".TB_PREF."suppliers.email, ".TB_PREF."suppliers.address, ".TB_PREF."suppliers.contact FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id AND ".TB_PREF."locations.loc_code = into_stock_location @@ -170,6 +170,7 @@ function print_po() { $myrow['contact_email'] = $myrow['email']; $myrow['DebtorName'] = $myrow['supp_name']; + if ($myrow['contact'] != '') $myrow['DebtorName'] = $myrow['contact']; $myrow['reference'] = $myrow['order_no']; $rep->End($email, $doc_Order_no . " " . $myrow['reference'], $myrow); } -- 2.30.2