addShortcode(); } protected function addShortcode(): void { add_shortcode("in-contact", [$this, "inContact"]); } public function inContact($atts) { $em_name = null; $em_mail = null; $em_message = null; $class = null; $html = null; $error = null; $body = null; $telefon = null; $mailResult = 0; $form_submitted = $_SERVER["REQUEST_METHOD"] === "POST"; if (!empty($_POST["website"])) { die(); } if ($form_submitted) { $emmsg = isset($_POST["emmsg"]) ? $_POST["emmsg"] : ""; if (!empty($_POST["em_name"])) { $em_name = $_POST["em_name"]; } else { $error .= esc_html__("Please enter your name", "in-contact") . "
"; } if (!empty($_POST["em_mail"])) { $em_mail = $_POST["em_mail"]; } else { $error .= esc_html__( "Please enter your email address", "in-contact", ) . "
"; } if (!empty($_POST["em_message"])) { $em_message = $_POST["em_message"]; } else { $error .= esc_html__("Please enter your message", "in-contact") . "
"; } $targetEmail = "To: Tylkofotografia <" . get_option("incontact-target-mail") . ">"; $mailResult = 0; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=" . get_bloginfo("charset") . "" . "\r\n"; $headers .= "From: " . $em_name . " <" . $em_mail . ">" . "\r\n"; $headers = [ "Content-Type: text/html; charset=UTF-8", "From: " . $em_name . " <" . $em_mail . ">", "Reply-To: " . $em_name . " <" . $em_mail . ">", ]; $emailTitle = __("New message from contact form", "in-contact"); $emailHeading = __("Contact details", "in-contact"); $emailNameLabel = __("Name and surname", "in-contact"); $emailEmailLabel = __("Email", "in-contact"); $emailMessageHeading = __("Message content", "in-contact"); $emailReplyLabel = __("Reply to message", "in-contact"); $emailFooter = __( "This email was generated automatically by the website contact form.", "in-contact", ); $emailRights = __("All rights reserved.", "in-contact"); $body = ' ' . esc_html($emailTitle) . '

📩 ' . esc_html($emailTitle) . '

' . esc_html($emailHeading) . '

' . esc_html($emailNameLabel) . ': {{IMIE_NAZWISKO}}

' . esc_html($emailEmailLabel) . ': {{EMAIL}}

📬 ' . esc_html($emailMessageHeading) . ':

{{WIADOMOSC}}

' . esc_html($emailReplyLabel) . '
'; $body = str_replace( [ "{{IMIE_NAZWISKO}}", "{{EMAIL}}", "{{TELEFON}}", "{{WIADOMOSC}}", "{{ROK}}", ], [ $em_name, $em_mail, $telefon, str_replace(["\r\n", "\r", "\n"], "
", $em_message), date("Y"), ], $body, ); $gRecaptchaResponse = isset($_POST["g-recaptcha-response"]) ? $_POST["g-recaptcha-response"] : ""; if (!empty($error)) { $html .= '"; } elseif ($emmsg == "true") { $secret = get_option("incontact-secret-key"); $response = null; if (get_option("incontact-site-key") != "") { $reCaptcha = new \ReCaptcha\ReCaptcha($secret); $resp = $reCaptcha ->setExpectedHostname($_SERVER["SERVER_NAME"]) ->verify($gRecaptchaResponse, $_SERVER["REMOTE_ADDR"]); if ($resp->isSuccess()) { $canSend = true; } else { $errors = $resp->getErrorCodes(); } } else { $canSend = true; } if ($canSend) { $mailResult = wp_mail( $targetEmail, $em_name, $body, $headers, ); } } } wp_enqueue_style("ContactCss", plugins_url("/css/cform.css", __FILE__)); if (get_option("incontact-site-key") != "") { $html .= ' ' . "\n"; } $html .= '
'; if ($mailResult == 1) { $html .= '"; } $html .= '
' . esc_html__("Please enter your name!", "in-contact") . '
' . esc_html__("Please enter your email address!", "in-contact") . '

' . get_option("incontact-form-message") . '

' . esc_html__("Please enter your message!", "in-contact") . '

'; return $html; } }