From 14a395359b2c2d3e99c7fd420fd3e9714975874c Mon Sep 17 00:00:00 2001 From: rm Date: Wed, 9 Nov 2011 14:14:06 +0100 Subject: [PATCH 1/4] Mail funktion set --- classes/mail.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 classes/mail.php diff --git a/classes/mail.php b/classes/mail.php new file mode 100644 index 0000000..47c29c2 --- /dev/null +++ b/classes/mail.php @@ -0,0 +1,84 @@ +to = $to; + } + + public function from($name, $email) + { + $this->from['name'] = $name; + $this->from['email'] = $email; + } + + public function subject($subject) + { + $this->subject = $subject; + } + + public function content($message) + { + $this->message = $message; + } + + public function attachment($fileURL) + { + $file = fopen($fileURL, ‘rb’); + $fileContent = fread($file, filesize($fileURL)); + fclose($file); + + $this->attachment = $fileContent; + $this->attname = basename($fileURL); + } + + public function send() + { + $header = 'from:' . $this->from['name'] . '<' . $this->from['email'] . '>' ; + $header .= 'Content-Type: text/plain; charset=UTF-8\r\n' . + 'Content-Transfer-Encoding: base64\r\n\r\n'; + + $content = ""; + if($this->attachment) + { + $semi_rand = md5(time()); + $mime_boundary = '==Multipart_Boundary_x'.$semi_rand.'x'; + + $headers .= '\nMIME-Version: 1.0\n' . + 'Content-Type: multipart/mixed;\n' . + 'boundary=" '. $mime_boundary .'"'; + + $this->attachment = chunk_split(base64_encode($this->attachment)); + $content .= '–'.$mime_boundary.'\n' . + 'Content-Type: application/pdf;\n' . + 'name="'. $this->attname .'"\n' . + 'Content-Disposition: attachment;\n' . + 'filename= "'. $this->attname .'"\n' . + 'Content-Transfer-Encoding: base64\n\n' . + $this->attachment . '\n\n' . + '-'.$mime_boundary.'-\n'; + } + if( mail($this->to,$this->subject, ,$this->message, $headers) ) + { + return TRUE; + } + else + { + return FALSE; + } + } + +} From 1a5c73f6375b69a91b07505a43c0d68ef0a26fea Mon Sep 17 00:00:00 2001 From: rm Date: Wed, 9 Nov 2011 14:16:39 +0100 Subject: [PATCH 2/4] Mail funktion set --- classes/mail.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/classes/mail.php b/classes/mail.php index 47c29c2..fcdd919 100644 --- a/classes/mail.php +++ b/classes/mail.php @@ -2,12 +2,12 @@ Class Mail { - protected $to = ""; - protected $from = Array(); - protected $subject = ""; - protected $message = ""; - protected $attachment = ""; - protected $attname = ""; + private $to = ""; + private $from = Array(); + private $subject = ""; + private $message = ""; + private $attachment = ""; + private $attname = ""; public function __construct() { From ac9cdde8b1b7b9805e964767880033ba0da3406e Mon Sep 17 00:00:00 2001 From: rm Date: Wed, 9 Nov 2011 14:51:55 +0100 Subject: [PATCH 3/4] addslashes --- xsl/admin/bills.xsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xsl/admin/bills.xsl b/xsl/admin/bills.xsl index d917458..d15ed3b 100644 --- a/xsl/admin/bills.xsl +++ b/xsl/admin/bills.xsl @@ -76,9 +76,9 @@ SEK - Link + Link - [Details] + [Details] [Mark as paid] From c31e74e17d5ea0c484cbb5bc497d3711bf2018b1 Mon Sep 17 00:00:00 2001 From: rm Date: Thu, 10 Nov 2011 13:09:11 +0100 Subject: [PATCH 4/4] =?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; }