1
+ <?php
2
+ /**
3
+ */
4
+ function EmailText($from, $to, $subj, $text, $replyto, $fname, $headers, $file, $filename)
5
+ {
6
+ $uniq = strtoupper(uniqid(time()));
7
+ $subj = '=?UTF-8?B?'.base64_encode($subj).'?=';
8
+
9
+ $head = "From: =?utf-8?B?".base64_encode(trim($fname))."?= <".trim($from).">\n";
10
+ $head .= "Subject: ".$subj."\n";
11
+ $head .= "Reply-To: ".$replyto."\n";
12
+ $head .= "Return-Path: ".$replyto."\n";
13
+
14
+ //$head .= "X-Mailer: PHP/" . phpversion()."\n";
15
+
16
+ foreach ($headers as $header)
17
+ {
18
+ $head .= $header."\n";
19
+ }
20
+ $head .= "Mime-Version: 1.0\n";
21
+ $head .= "Content-Type:multipart/mixed;";
22
+ $head .= "boundary=\"----------".$uniq."\"\n\n";
23
+
24
+ $body = "------------".$uniq."\nContent-Type: text/plain; charset=utf-8\n";
25
+ $body .= "Content-Transfer-Encoding: 8bit\n\n".$text."\n\n";
26
+
27
+ $file = trim($file);
28
+ if (strlen($file) > 0)
29
+ {
30
+ $body .= "------------".$uniq."\n";
31
+ $body .= "Content-Type: application/octet-stream;";
32
+ $body .= "name=\"".$filename."\"\n";
33
+ $body .= "Content-Transfer-Encoding: base64\n";
34
+ $body .= "Content-Disposition: attachment;";
35
+ $body .= "filename=\"".$filename."\"\n\n";
36
+ $body .= chunk_split(base64_encode($file))."\n";
37
+ $body .= "------------".$uniq."\n";
38
+ }
39
+ return mail("$to", "$subj", $body, $head);
40
+ }
41
+
42
+ /**
43
+ */
44
+ function EmailHtml($from, $to, $subj, $text, $replyto, $fname, $headers, $file, $filename)
45
+ {
46
+ $uniq = strtoupper(uniqid(time()));
47
+ $subj = '=?UTF-8?B?'.base64_encode($subj).'?=';
48
+
49
+ $head = "From: =?utf-8?B?".base64_encode(trim($fname))."?= <".trim($from).">\n";
50
+ $head .= "Subject: ".$subj."\n";
51
+ $head .= "Reply-To: ".$replyto."\n";
52
+ $head .= "Return-Path: ".$replyto."\n";
53
+
54
+ foreach ($headers as $header)
55
+ {
56
+ $head .= $header."\n";
57
+ }
58
+ $head .= "Mime-Version: 1.0\n";
59
+
60
+ $head .= "Content-Type:multipart/mixed;";
61
+ $head .= "boundary=\"----------".$uniq."\"\n\n";
62
+ $body = "------------".$uniq."\nContent-Type: text/html; charset=utf-8;\n";
63
+ $body .= "Content-Transfer-Encoding: 8bit\n\n".mb_convert_encoding($text, "HTML-ENTITIES", "UTF-8")."\n\n";
64
+
65
+ $file = trim($file);
66
+ if (strlen($file) > 0)
67
+ {
68
+ $body .= "------------".$uniq."\n";
69
+ $body .= "Content-Type: application/octet-stream;";
70
+ $body .= "name=\"".$filename."\"\n";
71
+ $body .= "Content-Transfer-Encoding: base64\n";
72
+ $body .= "Content-Disposition: attachment;";
73
+ $body .= "filename=\"".$filename."\"\n\n";
74
+ $body .= chunk_split(base64_encode($file))."\n";
75
+ $body .= "------------".$uniq."\n";
76
+ }
77
+ return mail("$to", "$subj", $body, $head);
78
+ }
79
+
80
+ @$filename = trim($_POST['filename']);
81
+ @$file = trim($_POST['file']);
82
+ @$email = trim($_POST['email']);
83
+ @$type = trim($_POST['type']);
84
+ @$subj = trim($_POST['subj']);
85
+ @$fname = trim($_POST['fname']);
86
+ @$replyto = trim($_POST['replyto']);
87
+ @$from = trim($_POST['from']);
88
+ @$text = trim($_POST['text']);
89
+ @$headers = json_decode(trim($_POST['headers']));
90
+
91
+ if (preg_match("~txt~is", $type))
92
+ {
93
+ $text = strip_tags($text);
94
+ $ok = EmailText($from, $email, $subj, $text, $replyto, $fname, $headers, $file, $filename);
95
+ print $ok ? 'OK' : 'FAIL';
96
+ }
97
+
98
+ if (preg_match("~html~is", $type))
99
+ {
100
+ $ok = EmailHtml($from, $email, $subj, $text, $replyto, $fname, $headers, $file, $filename);
101
+ print $ok ? 'OK' : 'FAIL';
102
+ }
103
+ ?>
0 commit comments