From c31e74e17d5ea0c484cbb5bc497d3711bf2018b1 Mon Sep 17 00:00:00 2001 From: rm Date: Thu, 10 Nov 2011 13:09:11 +0100 Subject: [PATCH] =?UTF-8?q?forts=C3=A4tter=20p=C3=A5=20mail-funktionen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/controller/admin/bills.php | 27 +++++++++++++++++++++++++++ classes/mail.php | 13 +++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/classes/controller/admin/bills.php b/classes/controller/admin/bills.php index 0ea0498..70ef583 100644 --- a/classes/controller/admin/bills.php +++ b/classes/controller/admin/bills.php @@ -14,6 +14,32 @@ public function action_index() $this->xml_content_bills = $this->xml_content->appendChild($this->dom->createElement('bills')); xml::to_XML(Bills::get(), $this->xml_content_bills, 'bill', 'id'); } + + public function action_email() + { + //Get the bill data. + $bill = New Bill($_GET['invoice']); + $costumer = $bill->get_customer_data('costumer_email'); + + $mail = new Mail(); + $mail->from('Larv IT AB', 'info@larvit.se'); + $mail->to($costumer); + $mail->subject('Invoice from Larv IT'); + $mail->content('Invoice sent'); + $mail->attachment(url::base('http',FALSE).'/user_content/pdf/bill_'.$_GET['invoice'].'.pdf'); + + if($mail->send()) + { + die('Email was sent and costumer = '.$costumer); + } + else + { + die('email was not sent and costumer = '.$costumer); + } + + // if email sent then update bills.invoice_sent with CURRENT_TIMESTAMP + } + public function action_new_bill() { @@ -109,5 +135,6 @@ public function action_mark_as_paid($details) $bill->pay($pay_date); $this->redirect(); } + } diff --git a/classes/mail.php b/classes/mail.php index fcdd919..5ec07c6 100644 --- a/classes/mail.php +++ b/classes/mail.php @@ -1,6 +1,6 @@ attachment = $fileContent; @@ -47,7 +47,8 @@ public function attachment($fileURL) public function send() { - $header = 'from:' . $this->from['name'] . '<' . $this->from['email'] . '>' ; + $header = 'From: "'.$this->from['name'].'" <'.$this->from['email'].'>\r\n'; + $header .= 'Reply-To: '.$this->from['email'].'\r\n'; $header .= 'Content-Type: text/plain; charset=UTF-8\r\n' . 'Content-Transfer-Encoding: base64\r\n\r\n'; @@ -57,7 +58,7 @@ public function send() $semi_rand = md5(time()); $mime_boundary = '==Multipart_Boundary_x'.$semi_rand.'x'; - $headers .= '\nMIME-Version: 1.0\n' . + $header .= '\nMIME-Version: 1.0\n' . 'Content-Type: multipart/mixed;\n' . 'boundary=" '. $mime_boundary .'"'; @@ -71,7 +72,7 @@ public function send() $this->attachment . '\n\n' . '-'.$mime_boundary.'-\n'; } - if( mail($this->to,$this->subject, ,$this->message, $headers) ) + if( mail($this->to,$this->subject, $this->message, $header) ) { return TRUE; }