r66: Moving all DB stuff to be handled by ISSO. Working with our one big $bugsys...
[bugdar.git] / includes / functions_mail.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 // ########################### Start mymail ##########################
14 function mymail($toemail, $subject, $message, $fromemail = '', $headers = '', $fparam = true)
15 {
16 global $bugsys;
17
18 // Make sure sendmail is at our disposal
19 if (!(@ini_get('sendmail_path')))
20 {
21 return false;
22 }
23
24 // Work out our sender
25 $fromemail = fetch_first_line($fromemail);
26 if ($fromemail == -1 OR !$fromemail)
27 {
28 if ($bugsys->options['webmasteremail'])
29 {
30 $fromemail = fetch_first_line($bugsys->options['webmasteremail']);
31 }
32 else
33 {
34 // Do we want a sender?
35 if ($fparam)
36 {
37 return false;
38 }
39 }
40 }
41
42 // Work out the recipient
43 $toemail = fetch_first_line($toemail);
44 if (!$toemail)
45 {
46 return false;
47 }
48
49 // Work out the subject
50 $subject = fetch_first_line($subject);
51 if (!$subject)
52 {
53 $subject = $bugsys->options['trackertitle'] . ' Notification';
54 }
55
56 // Work out the body
57 $message = convert_standard_line_breaks($message);
58 if (!$message)
59 {
60 return false;
61 }
62
63 // Construct mail headers
64 $headers = convert_standard_line_breaks($headers, "\n");
65 $headers .= "From: \"$fromemail\" <" . $bugsys->options['webmasteremail'] . ">\n";
66 $headers .= "Return-Path: " . $bugsys->options['webmasteremail'] . "\n";
67 $headers .= "X-Mailer: BugStrike [#]version[#] Mail\n";
68 $headers .= "Content-Type: text/plain; charset=\"" . $bugsys->options['lang_charset'] . "\"\n";
69 $headers .= "Content-Transfer-Encoding: 7bit\n";
70
71 if ($fparam)
72 {
73 mail($toemail, $subject, $message, trim($headers), "-f $fromemail");
74 }
75 else
76 {
77 mail($toemail, $subject, $message, trim($headers));
78 }
79 }
80
81 // ###################### Start fetch_first_line #####################
82 function fetch_first_line($text)
83 {
84 $broken = explode("\r\n", convert_standard_line_breaks($text));
85 return $broken[0];
86 }
87
88 // ################ Start convert_standard_line_breaks ###############
89 function convert_standard_line_breaks($text, $convert_to = "\r\n")
90 {
91 return preg_replace("#(\r|\n|\r\n)#s", $convert_to, trim($text));
92 }
93
94 /*=====================================================================*\
95 || ###################################################################
96 || # $HeadURL$
97 || # $Id$
98 || ###################################################################
99 \*=====================================================================*/
100 ?>