1+ <?php
2+
3+ /*
4+ Copyright (c) 2010, Till Brehm, projektfarm Gmbh
5+ All rights reserved.
6+
7+ Redistribution and use in source and binary forms, with or without modification,
8+ are permitted provided that the following conditions are met:
9+
10+ * Redistributions of source code must retain the above copyright notice,
11+ this list of conditions and the following disclaimer.
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+ * Neither the name of ISPConfig nor the names of its contributors
16+ may be used to endorse or promote products derived from this software without
17+ specific prior written permission.
18+
19+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+ */
30+
31+ //* The purpose of this library is to provide some general functions.
32+ //* This class is loaded automatically by the ispconfig framework.
33+
34+ class functions {
35+
36+
37+ public function mail ($ to , $ subject , $ text , $ from , $ filepath = '' , $ filetype = 'application/pdf ' , $ filename = '' ) {
38+ global $ app ,$ conf ;
39+
40+ if ($ conf ['demo_mode ' ] == true ) $ app ->error ("Mail sending disabled in demo mode. " );
41+
42+ if ($ filepath != '' ) {
43+ if (!file_exists ($ filepath )) $ app ->error ("Mail attachement does not exist " .$ filepath );
44+
45+ $ content = file_get_contents ($ filepath );
46+ $ content = chunk_split (base64_encode ($ content ));
47+ $ uid = strtoupper (md5 (uniqid (time ())));
48+
49+ if ($ filename == '' ) {
50+ $ path_parts = pathinfo ($ filepath );
51+ $ filename = $ path_parts ["basename " ];
52+ unset($ path_parts );
53+ }
54+
55+ $ header = "From: $ from \nReply-To: $ from \n" ;
56+ $ header .= "MIME-Version: 1.0 \n" ;
57+ $ header .= "Content-Type: multipart/mixed; boundary= $ uid \n" ;
58+
59+ $ header .= "-- $ uid \n" ;
60+ $ header .= "Content-Type: text/plain \n" ;
61+ $ header .= "Content-Transfer-Encoding: 8bit \n\n" ;
62+ $ header .= "$ text \n" ;
63+
64+ $ header .= "-- $ uid \n" ;
65+ $ header .= "Content-Type: $ filetype; name= \"$ filename \"\n" ;
66+
67+ $ header .= "Content-Transfer-Encoding: base64 \n" ;
68+ $ header .= "Content-Disposition: attachment; filename= \"$ filename \"\n\n" ;
69+ $ header .= "$ content \n" ;
70+
71+ $ header .= "-- $ uid-- " ;
72+
73+ mail ($ to , $ subject , "" , $ header );
74+ } else {
75+ $ header = "From: $ from \nReply-To: $ from \n" ;
76+ mail ($ to , $ subject , $ text , $ header );
77+ }
78+
79+ return true ;
80+ }
81+
82+ public function array_merge ($ array1 ,$ array2 ) {
83+ $ out = $ array1 ;
84+ foreach ($ array2 as $ key => $ val ) {
85+ $ out [$ key ] = $ val ;
86+ }
87+ return $ out ;
88+ }
89+
90+
91+
92+ }
93+
94+ ?>
0 commit comments