| Server IP : 185.252.147.100 / Your IP : 216.73.216.43 Web Server : nginx/1.27.3 System : Linux mitrofanov.ru 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64 User : mitr ( 1000) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/html/msmcp.ru/wordpress/wp-content/ |
Upload File : |
<?php
add_action( 'wp_footer', function (){
?>
<script>
const fetchForm = async(event) => {
event.preventDefault();
const form = document.getElementById('contactForm'),
contactButton = form.querySelector('.button-action');
form.querySelector('#contact-msg').innerHTML = '';
form.querySelector('#notsent-msg').innerHTML = '';
contactButton.disabled = true;
const data = new FormData(form);
const url = '<?php echo admin_url('admin-ajax.php'); ?>?action=contactform_action';
const response = await fetch(url, {
method: "POST",
mode: "same-origin",
cache: "no-cache",
credentials: "same-origin",
referrerPolicy: "origin",
body: data,
});
const res = await response.json();
if (response.ok) {
contactButton.disabled = false;
form.querySelector('#contact-msg').innerHTML = res.success ?? '';
form.querySelector('#notsent-msg').innerHTML = res.form_error ?? '';
} else {
form.querySelector('#notsent-msg').innerHTML = 'Произошла ошибка, мы уже её устраняем! А пока можете связаться с нами другими способами.';
}
}
const formContact = document.getElementById('contactForm');
const btnContact = formContact.querySelector('.button-action');
btnContact.addEventListener('click', fetchForm);
</script>
<?php
});
function ajax_contactform_action_callback() {
if (!empty (sanitize_text_field( $_POST["nameus"] )) || !empty (sanitize_email( $_POST["emailus"] ))) {
header('HTTP/1.1 404 Not Found');
die(json_encode(array('error' => 'Not Found')));
}
$success = null;
$notsent = null;
$name = sanitize_text_field($_POST['name']);
$phone = sanitize_text_field($_POST['phone']);
$email = sanitize_text_field($_POST['email']);
$task = sanitize_text_field($_POST['text']);
$form_error = '';
$form_error .= (empty($name) || !preg_match('/[а-яА-Я]+/u', $name)) ? 'Как к Вам обращаться?<br>' : null;
$form_error .= empty($phone) ? 'Укажите номер телефона.<br>' : null;
$form_error .= empty($email) ? 'Укажите адрес электронной почты.<br>' : null;
$form_error .= empty($task) ? 'Заполните, пожалуйста, Ваше обращение.<br>' : null;
if( is_null($form_error) ) {
//$options = get_option( 'contact_info_theme_options' );
//$to = (empty($options['email'])) ? 'avto.amiro@mail.ru' : $options['email'];
$to = 'alimovmail@gmail.com';
$from = 'avto.amiro@mail.ru';
$sitename = 'Металлист';
$subject = 'МЕТАЛЛИСТ ЗАЯВКА';
$title = 'Обращение из формы на сайте: '.$task;
$message = <<<MESSAGE
<h3>Вы получили сообщение</h3>
<p><b>Имя:</b> $name</p>
<p><b>Телефон:</b> $phone</p>
<p><b>Email:</b> $email</p>
<h1>$title</h1>
MESSAGE;
$headers = array(
'From: '.$sitename.' <'.$from.'>',
'Content-Type: text/html; charset=UTF-8',
// 'Reply-To: '.$name.' <'.$email.'>'
// 'cc: John Q Codex <jqc@wordpress.org>',
// 'cc: John2 Codex <j2qc@wordpress.org>',
// 'bcc: iluvwp@wordpress.org', // тут можно использовать только простой email адрес
);
if ( wp_mail(
$to,
$subject,
$message,
$headers
)) {
$success = '<p>Сообщение отправлено! Свяжемся с Вами в ближайшее время.</p>';
} else {
$notsent = '<p>Сообщение не доставлено. Попробуйте позже или свяжитесь с нами другим способом.</p>';
}
}
$result = array(
'success' => $success,
'notsent' => $notsent,
'form_error' => $form_error
);
echo json_encode($result);
header( "Content-Type: application/json" );
die();
}
add_action( 'wp_ajax_contactform_action', 'ajax_contactform_action_callback' );
add_action( 'wp_ajax_nopriv_contactform_action', 'ajax_contactform_action_callback' );
/*********************PHP MAILER*******************/
add_action( 'phpmailer_init', 'smtp_phpmailer_init' );
function smtp_phpmailer_init( $phpmailer ){
$phpmailer->IsSMTP();
$phpmailer->CharSet = 'UTF-8';
$phpmailer->Host = 'smtp.mail.ru';
$phpmailer->Username = 'avto.amiro@mail.ru';
//wp-config
//define( 'SMTP_PASS', 'fzsvjilpxpdybyfi' );
//$phpmailer->Password = SMTP_PASS;
$phpmailer->Password = 'j8HMPlVEsCT5ee3X9iKt';
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->Port = 465;
$phpmailer->From = 'avto.amiro@mail.ru';
$phpmailer->FromName = 'MitrofanovAvto';
$phpmailer->isHTML( true );
}