$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@vetrivalindia.com';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Vetrival Website Query Form';
$message = 'Values submitted from website form:';
$success_url = './Success1.html';
$error_url = './Error1.html';
$autoresponder_from = 'info@vetrivalindia.com';
$autoresponder_name = 'Vetrival India Assitant';
$autoresponder_to = isset($_POST['email']) ? $_POST['email'] : $mailfrom;
$autoresponder_subject = 'Thank You for Contact Us';
$autoresponder_message = 'Hello ther,Thank You So Much for contacting us. Will revert back to you shortly.';
$eol = "\r\n";
$error = '';
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response", "h-captcha-response");
$mail = new PHPMailer(true);
try
{
$mail->IsSMTP();
$mail->Host = '';
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->Subject = stripslashes($subject);
$mail->From = $mailfrom;
$mail->FromName = $mailfrom;
$mailto_array = explode(",", $mailto);
for ($i = 0; $i < count($mailto_array); $i++)
{
if(trim($mailto_array[$i]) != "")
{
$mail->AddAddress($mailto_array[$i], "");
}
}
if (!validateEmail($mailfrom))
{
$error .= "The specified email address (" . $mailfrom . ") is invalid!\n
";
throw new Exception($error);
}
$mail->AddReplyTo($mailfrom);
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$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;
}
}
}
$mail->CharSet = 'ISO-8859-1';
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if (is_array($_FILES[$key]['name']))
{
$count = count($_FILES[$key]['name']);
for ($file = 0; $file < $count; $file++)
{
if ($_FILES[$key]['error'][$file] == 0)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'][$file], $_FILES[$key]['name'][$file]);
}
}
}
else
{
if ($_FILES[$key]['error'] == 0)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
}
}
}
}
$mail->WordWrap = 80;
$mail->Body = $message;
$mail->Send();
$mail->ClearAddresses();
$mail->ClearAttachments();
$mail->ClearReplyTos();
$autoresponder_subject = replaceVariables($autoresponder_subject);
$mail->Subject = stripslashes($autoresponder_subject);
$mail->From = $autoresponder_from;
$mail->FromName = $autoresponder_name;
$mail->AddAddress($autoresponder_to, "");
$mail->AddReplyTo($autoresponder_from);
$autoresponder_message = replaceVariables($autoresponder_message);
$autoresponder_message = stripslashes($autoresponder_message);
$mail->MsgHTML($autoresponder_message);
$mail->IsHTML(true);
$mail->Send();
header('Location: '.$success_url);
}
catch (Exception $e)
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $e->getMessage(), $errorcode);
echo $errorcode;
}
exit;
}
?>