Hi all,
I have an order form that I created, it has no database connection just a simple form to mail function that send the order to me by email and a copy of the order to the client.
The problem I am having is I have constructed an XML function that I want to process based on that visitor inputting his/her username and pasword. The pass and use match then the XML executes and upgrades their account automatically on the server. How do I break down this process by not executing the XML until the mail function is complete?
<?php
if (isset($_POST['submit'])) {
require_once('recaptchalib.php');
$privatekey = "???";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("Opps, the captcha image was incorrect. Go <a href=\"#\" onclick=\"history.go(-1);return false;\">back</a> and try again.");
} else {
if ($_POST['name'] != "") {
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
if ($name == "") {
$errors .= 'Please enter a valid name.<br/><br/>';
}
} else {
$errors .= 'Please enter your name.<br/>';
}
if ($_POST['email'] != "") {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
}
} else {
$errors .= 'Please enter your email address.<br/>';
}
if ($_POST['username'] != "") {
$message = "--$mime_boundary\n";
$message .= "Dear ?????,\n\n";
$message .= "You have received the following order\n\n";
$message .= "Full name: $name:\n\n";
$message .= "Username: ";
$message .= $_POST['username']. "\n\n";
$message .= "Email address: $email\n\n";
$message .= "Thank You.\n\n";
$replymessage = "Hi $name,\n\n
Thank you for placing your order .\n\n
Whats Next?\n\n
14 Day trial - your trial starts today, absolutely free of charge. If during the 14 days you feel that you no longer require the ????? then drop us an email through our support request to cancel.\n\n
You account will be setup within the next 4 hours
--------------------------------------------------
Subject: $subject
Query:
$message
--------------------------------------------------
Thank you";
if ($message == "") {
$errors .= 'Please enter a valid username.<br/><br/>';
}
} else {
$errors .= 'Please enter your username.<br/>';
}
if (!$errors) {
$to = "???";
$subject = "Order";
$headers = "From: $email";
$header = "From: $to";
mail($to,$subject,$message,$headers);
mail($email,$subject,$replymessage,$header);
echo '<p class="bold">Thank you!</p>';
} else {
echo '<div style="color: red">' . $errors . '<br/></div>';
}
}
} else {
?>
<form name="secureform" action="order" method="post" class="order" >
By completing this order you agree to our standard <a href="<?php echo $url; ?>/policy/terms/" target="blank">terms</a>.</br /></br /> All orders have a 14 day trial prior to billing.</br /></br />
Full name: *<br /><input type="text" name="name" size="25" class="formtext"/><br />
Account username: *<br /><input type="text" name="username" size="25" class="formtext"/><br />
Email Address: *<br /><input type="text" name="email" size="35" class="formtext"/><br /><br />
<?php
require_once('recaptchalib.php');
$publickey = "??????";
echo recaptcha_get_html($publickey);
?>
<br />
<input type="submit" name="submit" value="Place order" class="buttonhome" />
<h4>Note:</h4>
</form>
<br /><br />
<?php
}
?>
and this is my XML code wrapped in php
<?
error_reporting(0);
$name = $_POST ['username'];
$auth = $_POST ['pass'];
$request = construct_xml($name, $auth);
$response = check_availability($request);
$available = parse_response($response);
if ($available == 1) {
echo "";
}
else {
echo " <a href=\"#\" onclick=\"history.go(-1);return false;\">BACK</a></h3>\n ";
}
function construct_xml ($name, $auth) {
return <<<XML
<?xml version='1.0' encoding='utf-8' ?>
<rpc module='order' method='Install' version='1.0'>
<auth>
<username>$name</username>
<password>$auth</password>
</auth>
<username datatype='username'>$name</username>
</rpc>
XML;
}
function check_availability ($request) {
$header .= "POST / HTTP/1.0\r\n";
$header .= "Content-Type: text/xml\r\n";
$header .= "Content-Length: " . strlen($request) . "\r\n\r\n";
$fp = fsockopen("xmlrpc.******.co.uk", ******, $errno, $errstr, 30);
if ($fp) {
fputs ($fp, $header . $request);
while (!feof($fp)) {
$response .= fgets($fp, 2291);
}
fclose ($fp);
$pos = strpos($response, "\r\n\r\n");
$response = substr($response, $pos + 4);
}
return $response;
}
function parse_response ($xml) {
$xml = new SimpleXMLElement($xml);
$code = $xml->response['code'];
$text = $xml->response['text'];
if ($code != 0) {
echo "Error occurred: $text\n";
exit;
}
return $xml->availability;
}
?>