$value)
{
if (is_array($value))
{
$value = implode(",", $value);
}
$name = "$" . $key;
$code = str_replace($name, $value, $code);
}
$code = str_replace('$ipaddress', $_SERVER['REMOTE_ADDR'], $code);
return $code;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form2')
{
$mailto = 'info@yogarentalcars.com';
$mailfrom = 'info@yogarentalcars.com';
ini_set('sendmail_from', $mailfrom);
$mailcc = 'yogarentalcars@gmail.com';
$mailname = 'Car Rental Booking';
$subject = 'Car Rental Booking';
$message = 'Values submitted from web site form:';
$success_url = './Contact-succes.php';
$error_url = './contact-error.php';
$eol = "\n";
$error = '';
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response", "h-captcha-response");
$boundary = md5(uniqid(time()));
$header = 'From: '.$mailname.' <'.$mailfrom.'>'.$eol;
$header .= 'Reply-To: '.Car Rental Booking Form.$eol;
$header .= 'Cc: '.$mailcc.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
try
{
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address (" . $mailfrom . ") is invalid!\n
";
throw new Exception($error);
}
$sender_domain = substr($mailfrom, strpos($mailfrom, '@') + 1);
if (!checkdnsrr($sender_domain, "MX"))
{
if (!(checkdnsrr($sender_domain, "A")) or !(checkdnsrr($sender_domain, "AAAA")))
{
$error .= "No email can be sent to the specified domain (" . $sender_domain . ").\n
";
throw new Exception($error);
}
}
foreach ($_POST as $key => $value)
{
if (preg_match('/www\.|http:|https:/i', $value))
{
$error .= "URLs are not allowed!\n
";
throw new Exception($error);
break;
}
}
if (empty($_POST['Name :']))
{
$error .= "Please enter a value for the \"Name :\" field.\n
";
}
if (!preg_match("/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i", $_POST['Email :']))
{
$error .= "Please enter a valid email address.\n
";
}
if (empty($_POST['Email :']))
{
$error .= "Please enter a value for the \"Email :\" field.\n
";
}
if (empty($_POST['country']))
{
$error .= "Please select one of the \"country\" options.\n
";
}
if (empty($_POST['Pax :']))
{
$error .= "Please enter a value for the \"Pax :\" field.\n
";
}
if (empty($_POST['Type Car :']))
{
$error .= "Please enter a value for the \"Type Car :\" field.\n
";
}
if (empty($_POST['Type Rental :']))
{
$error .= "Please select one of the \"Type Rental :\" options.\n
";
}
if (empty($_POST['Pickup']))
{
$error .= "Please select one of the \"Pickup\" options.\n
";
}
if (empty($_POST['Mobile Phone :']))
{
$error .= "Please enter a value for the \"Mobile Phone :\" field.\n
";
}
if (empty($_POST['Message']))
{
$error .= "Please enter a value for the \"Message\" field.\n
";
}
if (!empty($error))
{
throw new Exception($error);
}
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
$message .= "Referer : ";
$message .= $_SERVER['SERVER_NAME'];
$message .= $_SERVER['PHP_SELF'];
$message .= $eol;
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
}
}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=UTF-8'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0)
{
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != '')
{
mail("{$mailto} <{$mailto}>", $subject, $body, $header, '-f'.$mailfrom);
}
$successcode = file_get_contents($success_url);
$successcode = ReplaceVariables($successcode);
echo $successcode;
}
catch (Exception $e)
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $e->getMessage(), $errorcode);
echo $errorcode;
}
exit;
}
?>