| Server IP : 185.252.147.100 / Your IP : 216.73.217.33 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/consulting/wordpress/wp-content/plugins/da-contact-form/ |
Upload File : |
<?php
/*
* @wordpress-plugin
* Plugin Name: DA Contact Form
* Plugin URI: http://k-45.ru
* Description: <strong>Отправка данных в контактных формах</strong> | Обработка и отправка данных из контакт-форм на сайте
* Version: 1.0.0
* Author: @daali
* Author URI: @daali
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if (!function_exists('da_cf_script')) {
function da_cf_script() {
wp_enqueue_script( 'da_best_form', plugins_url('assets/da_cf.min.js', __FILE__), null, null, true );
wp_localize_script( 'da_best_form', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
}
add_action('wp_enqueue_scripts', 'da_cf_script');
add_shortcode('da_form_secure', 'contactFormNonce');
function contactFormNonce(){
$nonce = wp_nonce_field('da-contactform-nonce', '_cf_nonce', true, false);
return $nonce;
};
add_action( 'wp_ajax_submit_contact_form', 'ajax_submit_contact_form_callback' );
add_action( 'wp_ajax_nopriv_submit_contact_form', 'ajax_submit_contact_form_callback' );
function ajax_submit_contact_form_callback() {
//check_ajax_referer('da_nonce', 'nonce');
if (!wp_verify_nonce($_POST['_cf_nonce'], 'da-contactform-nonce')) {
echo json_encode( array( 'message' => 'Ошибка верификации' ) );
header( "Content-Type: application/json" );
die();
}
$post_data = array();
$message = <<<MESSAGE
<h3>Вы получили сообщение</h3>
<p>Данные формы:</p>
MESSAGE;
foreach ($_POST as $key => $value) {
// Skip the nonce and action fields
if ($key === 'nonce' || $key === 'action' || $key === '_cf_nonce' || $key === '_wp_http_referer') {
continue;
}
$sanitized_value = sanitize_text_field($value);
if (in_array($key, ['Имя', 'Телефон']) && empty($sanitized_value)) {
echo json_encode( array( 'notsent' => 'Проверьте, пожалуйста, правильно ли указаны имя и телефон.' ) );
header( "Content-Type: application/json" );
die();
}
$post_data[$key] = $sanitized_value;
$message .= "<p><strong>" . ucfirst($key) . ":</strong> " . $sanitized_value . "</p>";
}
$sitename = get_bloginfo( 'name' );
$from = 'avto.amiro@mail.ru';
$to = 'svm@dobrolom.com';
//$to = 'alimovmail@gmail.com';
$subject = $sitename . '- Сообщение';
$headers = array(
'From: ' . $sitename . ' <' .$from. '>',
'Content-Type: text/html; charset=UTF-8',
// 'Reply-To: '.$name.' <'.$email.'>'
// 'cc: John Q Codex <jqc@wordpress.org>',
'cc: Виталий Борисович <vit@dobrolom.com>',
// 'bcc: iluvwp@wordpress.org', // тут можно использовать только простой email адрес
);
if ( wp_mail(
$to,
$subject,
$message,
$headers
)) {
$post_data['success'] = '<p>Сообщение отправлено! Свяжемся с Вами в ближайшее время.</p>';
} else {
$post_data['notsent'] = '<p>Сообщение не доставлено. Попробуйте позже или свяжитесь с нами другим способом.</p>';
}
echo json_encode($post_data);
header( "Content-Type: application/json" );
die();
}
/*********************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 );
}