Reformat source code: demos
[plcapi.git] / demo / client / mail.php
1 <?php
2 // Allow users to see the source of this file even if PHP is not configured for it
3 if ((isset($HTTP_GET_VARS['showSource']) && $HTTP_GET_VARS['showSource']) ||
4     (isset($_GET['showSource']) && $_GET['showSource'])
5 ) {
6     highlight_file(__FILE__);
7     die();
8 }
9 ?>
10 <html>
11 <head><title>xmlrpc</title></head>
12 <body>
13 <h1>Mail demo</h1>
14
15 <p>This form enables you to send mail via an XML-RPC server. For public use
16     only the "Userland" server will work (see <a href="http://www.xmlrpc.com/discuss/msgReader$598">Dave Winer's
17         message</a>).
18     When you press <kbd>Send</kbd> this page will reload, showing you the XML-RPC request sent to the host server, the
19     XML-RPC response received and the internal evaluation done by the PHP implementation.</p>
20
21 <p>You can find the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
22     And the source to a functionally identical mail-by-XML-RPC server in the file <a
23         href="../server/server.php?showSource=1">server.php</a> included with the library (look for the 'mail_send'
24     method)</p>
25 <?php
26 include "xmlrpc.inc";
27
28 // Play nice to PHP 5 installations with REGISTER_LONG_ARRAYS off
29 if (!isset($HTTP_POST_VARS) && isset($_POST)) {
30     $HTTP_POST_VARS = $_POST;
31 }
32
33 if (isset($HTTP_POST_VARS["server"]) && $HTTP_POST_VARS["server"]) {
34     if ($HTTP_POST_VARS["server"] == "Userland") {
35         $XP = "/RPC2";
36         $XS = "206.204.24.2";
37     } else {
38         $XP = "/xmlrpc/server.php";
39         $XS = "pingu.heddley.com";
40     }
41     $f = new xmlrpcmsg('mail.send');
42     $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailto"]));
43     $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailsub"]));
44     $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailmsg"]));
45     $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailfrom"]));
46     $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailcc"]));
47     $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailbcc"]));
48     $f->addParam(new xmlrpcval("text/plain"));
49
50     $c = new xmlrpc_client($XP, $XS, 80);
51     $c->setDebug(2);
52     $r = &$c->send($f);
53     if (!$r->faultCode()) {
54         print "Mail sent OK<br/>\n";
55     } else {
56         print "<fonr color=\"red\">";
57         print "Mail send failed<br/>\n";
58         print "Fault: ";
59         print "Code: " . htmlspecialchars($r->faultCode()) .
60             " Reason: '" . htmlspecialchars($r->faultString()) . "'<br/>";
61         print "</font><br/>";
62     }
63 }
64 ?>
65 <form method="POST">
66     Server <select name="server">
67         <option value="Userland">Userland</option>
68         <option value="UsefulInc">UsefulInc private server</option>
69     </select>
70     <hr/>
71     From <input size="60" name="mailfrom" value=""/><br/>
72     <hr/>
73     To <input size="60" name="mailto" value=""/><br/>
74     Cc <input size="60" name="mailcc" value=""/><br/>
75     Bcc <input size="60" name="mailbcc" value=""/><br/>
76     <hr/>
77     Subject <input size="60" name="mailsub" value="A message from xmlrpc"/>
78     <hr/>
79     Body <textarea rows="7" cols="60" name="mailmsg">Your message here</textarea><br/>
80     <input type="Submit" value="Send"/>
81 </form>
82 </body>
83 </html>