<?php
$mailto = "admin@minibusik.net.ua";
$subject = "Заявка с сайта";
$message = "Обработать заявочку с сайта, пожалуйста:";
$header = "From: ".$_POST['email'];
foreach ($_POST as $key => $value)
{
if (!is_array($value))
{
$message .= "\n".$key." : ".$value;
}
else
{
foreach ($_POST[$key] as $itemvalue)
{
$message .= "\n".$key." : ".$itemvalue;
}
}
}
mail($mailto, $subject, stripslashes($message), $header);
?><?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require __DIR__.'/Exception.php';
require __DIR__.'/PHPMailer.php';
require __DIR__.'/SMTP.php';
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'layer2')
{
$mailto = 'admin@minibusik.net.ua';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Заявка';
$message = 'Заявка с сайта';
$success_url = './страница2.php';
$error_url = '';
$csvFile = "./formdata.csv";
$eol = "\n";
$error = '';
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$logdata = '';
$mail = new PHPMailer(true);
try
{
$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<br>";
throw new Exception($error);
}
$mail->AddReplyTo($mailfrom);
$message .= $eol;
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
$logdata .= ',';
if (is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
$logdata .= implode("|", $value);
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
$value = str_replace(",", " ", $value);
$logdata .= $value;
}
}
}
$logdata = str_replace("\r", "", $logdata);
$logdata = str_replace("\n", " ", $logdata);
$logdata .= "\r\n";
$handle = fopen($csvFile, 'a') or die("can't open file");
$logtime = date("Y-m-d H:i:s,");
fwrite($handle, $logtime);
fwrite($handle, $logdata);
fclose($handle);
$mail->CharSet = 'UTF-8';
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0)
{
if (is_array($_FILES[$key]['name']))
{
$count = count($_FILES[$key]['name']);
for ($file = 0; $file < $count; $file++)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'][$file], $_FILES[$key]['name'][$file]);
}
}
else
{
$mail->AddAttachment($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
}
}
}
}
$mail->WordWrap = 80;
$mail->Body = $message;
$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;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'layer3')
{
$mailto = 'admin@minibusik.net.ua';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Заявка';
$message = 'Заявка, обработать, пожалуйста.';
$success_url = './страница2.php';
$error_url = './index.php';
$eol = "\n";
$error = '';
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$mail = new PHPMailer(true);
try
{
$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<br>";
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 = 'UTF-8';
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0)
{
if (is_array($_FILES[$key]['name']))
{
$count = count($_FILES[$key]['name']);
for ($file = 0; $file < $count; $file++)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'][$file], $_FILES[$key]['name'][$file]);
}
}
else
{
$mail->AddAttachment($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
}
}
}
}
$mail->WordWrap = 80;
$mail->Body = $message;
$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;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form2')
{
$mailto = 'admin@minibusik.net.ua';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Заявка';
$message = 'Заявка с сайта, пожалуйста, обработать';
$success_url = './страница2.php';
$error_url = './index.php';
$eol = "\n";
$error = '';
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$mail = new PHPMailer(true);
try
{
$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<br>";
throw new Exception($error);
}
$mail->AddReplyTo($mailfrom);
$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 = 'UTF-8';
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0)
{
if (is_array($_FILES[$key]['name']))
{
$count = count($_FILES[$key]['name']);
for ($file = 0; $file < $count; $file++)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'][$file], $_FILES[$key]['name'][$file]);
}
}
else
{
$mail->AddAttachment($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
}
}
}
}
$mail->WordWrap = 80;
$mail->Body = $message;
$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;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">