32a4a1f0c5afdb2850acdfb4e7c73b5b15f46861
[plcapi.git] / demo / client / mail.php
1 <?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
2 <head><title>xmlrpc - Mail demo</title></head>
3 <body>
4 <h1>Mail demo</h1>
5
6 <p>This form enables you to send mail via an XML-RPC server.
7     When you press <kbd>Send</kbd> this page will reload, showing you the XML-RPC request sent to the host server, the
8     XML-RPC response received and the internal evaluation done by the PHP implementation.</p>
9
10 <p>You can see the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
11     And the source to a functionally identical mail-by-XML-RPC server in the file <a
12         href="../server/server.php?showSource=1">server.php</a> included with the library (look for the 'mail_send'
13     method)</p>
14 <?php
15
16 // Use the custom class autoloader. These two lines not needed when the phpxmlrpc library is installed using Composer
17 include_once __DIR__ . "/../../src/Autoloader.php";
18 PhpXmlRpc\Autoloader::register();
19
20 if (isset($_POST["mailto"]) && $_POST["mailto"]) {
21     $server = XMLRPCSERVER;
22     $req = new PhpXmlRpc\Request('mail.send', array(
23         new PhpXmlRpc\Value($_POST["mailto"]),
24         new PhpXmlRpc\Value($_POST["mailsub"]),
25         new PhpXmlRpc\Value($_POST["mailmsg"]),
26         new PhpXmlRpc\Value($_POST["mailfrom"]),
27         new PhpXmlRpc\Value($_POST["mailcc"]),
28         new PhpXmlRpc\Value($_POST["mailbcc"]),
29         new PhpXmlRpc\Value("text/plain")
30     ));
31
32     $client = new PhpXmlRpc\Client($server);
33     $client->setDebug(2);
34     $resp = $client->send($req);
35     if (!$resp->faultCode()) {
36         print "Mail sent OK<br/>\n";
37     } else {
38         print "<font color=\"red\">";
39         print "Mail send failed<br/>\n";
40         print "Fault: ";
41         print "Code: " . htmlspecialchars($resp->faultCode()) .
42             " Reason: '" . htmlspecialchars($resp->faultString()) . "'<br/>";
43         print "</font><br/>";
44     }
45 }
46 ?>
47 <form method="POST">
48     From <input size="60" name="mailfrom" value=""/><br/>
49     <hr/>
50     To <input size="60" name="mailto" value=""/><br/>
51     Cc <input size="60" name="mailcc" value=""/><br/>
52     Bcc <input size="60" name="mailbcc" value=""/><br/>
53     <hr/>
54     Subject <input size="60" name="mailsub" value="A message from xmlrpc"/>
55     <hr/>
56     Body <textarea rows="7" cols="60" name="mailmsg">Your message here</textarea><br/>
57     <input type="Submit" value="Send"/>
58 </form>
59 </body>
60 </html>