All mysql_-statments replaced by their corresponding mysqli_-statements
[cacert-devel.git] / includes / mysql.php.sample
1 <? /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 $_SESSION['mconn'] = mysqli_connect("127.0.0.1", "username", "password", "database");
20
21 // if (!$_SESSION['mconn']) {
22 // die('Connect Error (' . mysqli_connect_errno() . ') '
23 // . mysqli_connect_error());
24 // }
25
26 $_SESSION['_config']['normalhostname'] = "www.cacert.org";
27 $_SESSION['_config']['securehostname'] = "secure.cacert.org";
28 $_SESSION['_config']['tverify'] = "tverify.cacert.org";
29
30 function sendmail($to, $subject, $message, $from, $replyto = "", $toname = "", $fromname = "", $errorsto = "returns@cacert.org", $use_utf8 = true)
31 {
32 $lines = explode("\n", $message);
33 $message = "";
34 foreach($lines as $line)
35 {
36 $line = trim($line);
37 if($line == ".")
38 $message .= " .\n";
39 else
40 $message .= $line."\n";
41 }
42
43 if($fromname == "")
44 $fromname = $from;
45
46 $bits = explode(",", $from);
47 $from = addslashes($bits['0']);
48 $fromname = addslashes($fromname);
49
50 $smtp = fsockopen("localhost", 25);
51 if(!$smtp)
52 {
53 echo("Could not connect to mailserver at localhost:25\n");
54 return;
55 }
56 $InputBuffer = fgets($smtp, 1024);
57 fputs($smtp, "HELO www.cacert.org\r\n");
58 $InputBuffer = fgets($smtp, 1024);
59 fputs($smtp, "MAIL FROM:<returns@cacert.org>\r\n");
60 $InputBuffer = fgets($smtp, 1024);
61 $bits = explode(",", $to);
62 foreach($bits as $user)
63 fputs($smtp, "RCPT TO:<".trim($user).">\r\n");
64 $InputBuffer = fgets($smtp, 1024);
65 fputs($smtp, "DATA\r\n");
66 $InputBuffer = fgets($smtp, 1024);
67 fputs($smtp, "X-Mailer: CAcert.org Website\r\n");
68 if (array_key_exists("REMOTE_ADDR", $_SERVER))
69 fputs($smtp, "X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
70 fputs($smtp, "Sender: $errorsto\r\n");
71 fputs($smtp, "Errors-To: $errorsto\r\n");
72 if($replyto != "")
73 fputs($smtp, "Reply-To: $replyto\r\n");
74 else
75 fputs($smtp, "Reply-To: $from\r\n");
76 fputs($smtp, "From: $from\r\n");
77 fputs($smtp, "To: $to\r\n");
78 if(preg_match("/[^a-zA-Z0-9 .-\[\]!_@]/",$subject))
79 {
80 fputs($smtp, "Subject: =?utf-8?B?".base64_encode(recode("html..utf-8", $subject))."?=\r\n");
81 }
82 else
83 {
84 fputs($smtp, "Subject: $subject\r\n");
85 }
86 fputs($smtp, "Mime-Version: 1.0\r\n");
87 if($use_utf8)
88 {
89 fputs($smtp, "Content-Type: text/plain; charset=\"utf-8\"\r\n");
90 }
91 else
92 {
93 fputs($smtp, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
94 }
95 fputs($smtp, "Content-Transfer-Encoding: quoted-printable\r\n");
96 fputs($smtp, "Content-Disposition: inline\r\n");
97
98 // fputs($smtp, "Content-Transfer-Encoding: BASE64\r\n");
99 fputs($smtp, "\r\n");
100 // fputs($smtp, chunk_split(base64_encode(recode("html..utf-8", $message)))."\r\n.\r\n");
101 $encoded_lines = explode( "\n", str_replace("\r", "", $message) );
102 array_walk( $encoded_lines,
103 function (&$a) {
104 $a = quoted_printable_encode(recode("html..utf-8", $a));
105 });
106 $encoded_message = implode("\n", $encoded_lines);
107
108 $encoded_message = str_replace("\r.", "\r=2E", $encoded_message);
109 $encoded_message = str_replace("\n.", "\n=2E", $encoded_message);
110 fputs($smtp, $encoded_message);
111 fputs($smtp, "\r\n.\r\n");
112 fputs($smtp, "QUIT\n");
113 $InputBuffer = fgets($smtp, 1024);
114 fclose($smtp);
115 }
116
117 ?>