jablonka.czprosek.czf

freenet-router

Subversion Repositories:
[/] [trunk/] [freenet-router/] [var/] [www/] [freenet-router/] [Framework/] [Mailer.php] - Blame information for rev 2

 

Line No. Rev Author Line
12simandl<?php
2 
3namespace Phem;
4 
5use Phem\Environment\EnvironmentManager;
6 
7class Mailer
8{
9 public static function sendMail($to,$subject,$body,$headers = null)
10 {
11 if ($headers == null)
12 {
13 $headers = "MIME-Version: 1.0" . "\r\n";
14 $headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
15 
16 $headers .= 'From: <' . MAILFROM_ADDRESS . '>' . "\r\n";
17 }
18 
19 foreach ($to as $address)
20 {
21 // $logger = EnvironmentManager::getLogger();
22 if (mail($address, $subject, $body,$headers)) {
23 $status = "OK";
24 } else {
25 $status = "FAILED";
26 }
27 // $logger->append("Sending email","Status: ".$status." To: ".$address." Subject: ".$subject);
28 }
29 }
30 
31 public static function sendMailTextAttachement($to, $subject, $message, $attachement,$filename)
32 {
33 $content = chunk_split(base64_encode($attachement));
34 $uid = md5(uniqid(time()));
35 $header = "From: " . MAILFROM_ADDRESS . "\r\n"
36 . "MIME-Version: 1.0\r\n"
37 . "Content-Type: multipart/mixed; charset=utf-8; boundary=\"" . $uid . "\"\r\n\r\n"
38 . "This is a multi-part message in MIME format.\r\n\r\n"
39 . "--" . $uid . "\r\n"
40 . "Content-Type: text/html; charset=utf-8"."\r\n"
41 . "Content-Transfer-Encoding: 8bit"."\r\n\r\n"
42 . $message . "\r\n\r\n"
43 . "--" . $uid . "\r\n"
44 . "Content-Type: text/plain; charset=utf-8; name=\"".$filename."\"\r\n"
45 . "Content-Transfer-Encoding: base64\r\n"
46 . "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
47 . $content . "\r\n\r\n"
48 . "--" . $uid . "--";
49 self::sendMail($to, $subject, "", $header);
50 }
51 
52 public static function sendMailAttachment($to, $subject, $message, $attachement,$filename, $type = "text/html")
53 {
54 $content = chunk_split(base64_encode($attachement));
55 $uid = md5(uniqid(time()));
56 $header = "From: " . MAILFROM_ADDRESS . "\r\n"
57 . "MIME-Version: 1.0\r\n"
58 . "Content-Type: multipart/mixed; charset=utf-8; boundary=\"" . $uid . "\"\r\n\r\n"
59 . "This is a multi-part message in MIME format.\r\n\r\n"
60 . "--" . $uid . "\r\n"
61 . "Content-Type: text/html; charset=utf-8"."\r\n"
62 . "Content-Transfer-Encoding: 8bit"."\r\n\r\n"
63 . $message . "\r\n\r\n"
64 . "--" . $uid . "\r\n"
65 . "Content-Type: ".$type."; name=\"".$filename."\"\r\n"
66 . "Content-Transfer-Encoding: base64\r\n"
67 . "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
68 . $content . "\r\n\r\n"
69 . "--" . $uid . "--";
70 self::sendMail($to, $subject, "", $header);
71 }
72 
73 public static function sendMailTextAttachments($to, $subject, $message, $files)
74 {
75 $uid = md5(uniqid(time()));
76 $header = "From: " . MAILFROM_ADDRESS . "\r\n"
77 . "MIME-Version: 1.0\r\n"
78 . "Content-Type: multipart/mixed; charset=utf-8; boundary=\"" . $uid . "\"\r\n\r\n"
79 . "This is a multi-part message in MIME format.\r\n\r\n"
80 . "--" . $uid . "\r\n"
81 . "Content-Type: text/html; charset=utf-8"."\r\n"
82 . "Content-Transfer-Encoding: 8bit"."\r\n\r\n"
83 . $message . "\r\n\r\n";
84 foreach($files as $file){
85 $header.= "--" . $uid . "\r\n"
86 . "Content-Type: plain/text; charset=utf-8; name=\"".$file['name']."\"\r\n"
87 . "Content-Transfer-Encoding: base64\r\n"
88 . "Content-Disposition: attachment; filename=\"".$file['name']."\"\r\n\r\n"
89 . $file['content'] . "\r\n\r\n";
90 }
91 $header.= "--" . $uid . "--";
92 self::sendMail($to, $subject, "", $header);
93 }
94 
95}
96 

Powered by WebSVN 2.2.1