Skip to content

Commit

Permalink
fortsätter på mail-funktionen
Browse files Browse the repository at this point in the history
  • Loading branch information
rockymontana committed Nov 10, 2011
1 parent ac9cdde commit c31e74e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
27 changes: 27 additions & 0 deletions classes/controller/admin/bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]');
$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()
{
Expand Down Expand Up @@ -109,5 +135,6 @@ public function action_mark_as_paid($details)
$bill->pay($pay_date);
$this->redirect();
}


}
13 changes: 7 additions & 6 deletions classes/mail.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php defined('SYSPATH') or die('No direct script access.');

Class Mail {
class Mail extends Controller {

private $to = "";
private $from = Array();
Expand Down Expand Up @@ -37,8 +37,8 @@ public function content($message)

public function attachment($fileURL)
{
$file = fopen($fileURL, ‘rb’);
$fileContent = fread($file, filesize($fileURL));
$file = fopen($fileURL, 'rb');
$fileContent = stream_get_contents($file);
fclose($file);

$this->attachment = $fileContent;
Expand All @@ -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';

Expand All @@ -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 .'"';

Expand All @@ -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;
}
Expand Down

0 comments on commit c31e74e

Please sign in to comment.