Merge remote-tracking branch 'origin/bug-977' into release
[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'] = mysql_connect("127.0.0.1", "username", "password");
20 if ($_SESSION['mconn'] != FALSE)
21 {
22 mysql_select_db("database");
23 $_SESSION['mconn'] = TRUE;
24 }
25 $_SESSION['_config']['normalhostname'] = "www.cacert.org";
26 $_SESSION['_config']['securehostname'] = "secure.cacert.org";
27 $_SESSION['_config']['tverify'] = "tverify.cacert.org";
28
29 function sendmail($to, $subject, $message, $from, $replyto = "", $toname = "", $fromname = "", $errorsto = "returns@cacert.org", $extra="")
30 {
31 $lines = explode("\n", $message);
32 $message = "";
33 foreach($lines as $line)
34 {
35 $line = trim($line);
36 if($line == ".")
37 $message .= " .\n";
38 else
39 $message .= $line."\n";
40 }
41
42 if($fromname == "")
43 $fromname = $from;
44
45 $bits = explode(",", $from);
46 $from = addslashes($bits['0']);
47 $fromname = addslashes($fromname);
48
49 $smtp = fsockopen("localhost", 25);
50 if(!$smtp)
51 {
52 echo("Could not connect to mailserver at localhost:25\n");
53 return;
54 }
55 $InputBuffer = fgets($smtp, 1024);
56 fputs($smtp, "HELO www.cacert.org\r\n");
57 $InputBuffer = fgets($smtp, 1024);
58 fputs($smtp, "MAIL FROM:<returns@cacert.org>\r\n");
59 $InputBuffer = fgets($smtp, 1024);
60 $bits = explode(",", $to);
61 foreach($bits as $user)
62 fputs($smtp, "RCPT TO:<".trim($user).">\r\n");
63 $InputBuffer = fgets($smtp, 1024);
64 fputs($smtp, "DATA\r\n");
65 $InputBuffer = fgets($smtp, 1024);
66 fputs($smtp, "X-Mailer: CAcert.org Website\r\n");
67 fputs($smtp, "X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
68 fputs($smtp, "Sender: $errorsto\r\n");
69 fputs($smtp, "Errors-To: $errorsto\r\n");
70 if($replyto != "")
71 fputs($smtp, "Reply-To: $replyto\r\n");
72 else
73 fputs($smtp, "Reply-To: $from\r\n");
74 fputs($smtp, "From: $from\r\n");
75 fputs($smtp, "To: $to\r\n");
76 if(preg_match("/[^a-zA-Z0-9 .-\[\]!_@]/",$subject))
77 {
78 fputs($smtp, "Subject: =?utf-8?B?".base64_encode(recode("html..utf-8", $subject))."?=\r\n");
79 }
80 else
81 {
82 fputs($smtp, "Subject: $subject\r\n");
83 }
84 fputs($smtp, "Mime-Version: 1.0\r\n");
85 if($extra == "")
86 {
87 fputs($smtp, "Content-Type: text/plain; charset=\"utf-8\"\r\n");
88 fputs($smtp, "Content-Transfer-Encoding: 8bit\r\n");
89 } else {
90 fputs($smtp, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
91 fputs($smtp, "Content-Transfer-Encoding: quoted-printable\r\n");
92 fputs($smtp, "Content-Disposition: inline\r\n");
93 }
94 // fputs($smtp, "Content-Transfer-Encoding: BASE64\r\n");
95 fputs($smtp, "\r\n");
96 // fputs($smtp, chunk_split(base64_encode(recode("html..utf-8", $message)))."\r\n.\r\n");
97 fputs($smtp, recode("html..utf-8", $message)."\r\n.\r\n");
98 fputs($smtp, "QUIT\n");
99 $InputBuffer = fgets($smtp, 1024);
100 fclose($smtp);
101 }
102
103 ?>