<?php

include("funcs.php");

if (!ValidateReferer()) {
	header("Location: index$Lingua.php");
	die();
}

$mail_to = $HTTP_POST_VARS["mailto"];
if ($mailto == "") {
	$mail_to = "<<1-email_ordini>>";
}

$edisplay = "";

$cliente = GetCliente();
if ($cliente > 0) {
	$sql = "SELECT * FROM clienti WHERE cust_id='$cliente'";
	$result = mysql_query($sql);
	if ($row = mysql_fetch_array($result)) {
		$nome = $row['user'];
		if ($nome != "") {
			$edisplay = "Cliente: $nome\r\n";
		}
	}
}

foreach ($HTTP_POST_VARS as $strCampo=>$v) {
	if (substr($strCampo,0,9) == "edisplay_") {
		$edisplay .= substr($strCampo,9) . ": " . $v . "\r\n";
	}
}

$email = $HTTP_POST_VARS["Email"];
if ($email == "") {
	$email = $HTTP_POST_VARS["email"];
}
if ($email == "") {
	$email = $HTTP_POST_VARS["edisplay_Email"];
}
if ($email == "") {
	$email = $HTTP_POST_VARS["edisplay_email"];
}
if ($email == "") {
	$email = $mail_to;
}

$sendmail_subject = $HTTP_POST_VARS["subject"];
if ($sendmail_subject == "") {
	$sendmail_subject = "Richiesta info";
}

$response = $HTTP_POST_VARS["response"];
if ($response == "") {
	$response = "index$Lingua.php";
} else {
	$response = "login$Lingua.php?m=37&b=no&t=".rawurlencode($response);
}

$responsepage = $HTTP_POST_VARS["responsepage"];
if ($responsepage != "") {
	$response = $responsepage;
}

$sendmail_from = $email;
$sendmail_replyto = $email;

$info = "";

$info .= "------------------------------------------\r\n";
$info .= $edisplay;
$info .= "------------------------------------------\r\n\r\n";

mail($mail_to, $sendmail_subject, $info, "From: " . $sendmail_from . "\r\n" . "Reply-To: " . $sendmail_replyto . "");

header("Location: $response");
?>
