Created
May 9, 2019 04:45
-
-
Save Dziuperman/a45cfb6c8a1db4e16f42c8a568fba64f to your computer and use it in GitHub Desktop.
Форма обратной связи phpmailer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PHPMailer\PHPMailer\PHPMailer; | |
use PHPMailer\PHPMailer\Exception; | |
require 'PHPMailer/src/PHPMailer.php'; | |
require 'PHPMailer/src/Exception.php'; | |
require 'PHPMailer/src/SMTP.php'; | |
require_once "recaptchalib.php"; // recaptcha обработчик | |
$mail = new PHPMailer(true); | |
$mail->CharSet = 'utf-8'; | |
// Переменные | |
$recepient = "[email protected]"; | |
$sender = "[email protected]"; | |
$siteName = "Синто"; | |
$name = trim($_POST["name"]); | |
$phone = trim($_POST["phone"]); | |
$email = trim($_POST["email"]); | |
$message = trim($_POST["message"]); | |
$textMessage = "Имя: $name<br/>Телефон: $phone<br/>Email: $email<br/><br/>Описание проблемы: $message"; | |
$pagetitle = "Заявка с сайта \"$siteName\""; | |
// Настройки | |
$mail->isSMTP(); | |
$mail->Host = 'smtp.yandex.ru'; | |
$mail->SMTPAuth = true; | |
$mail->Username = '[email protected]'; // Ваш логин в Яндексе. Именно логин, без @yandex.ru | |
$mail->Password = 'd23oif23mce12jwq'; // Ваш пароль | |
$mail->SMTPSecure = 'ssl'; | |
$mail->Port = 465; | |
$mail->setFrom($sender); // Ваш Email (отправителя) | |
$mail->addAddress($recepient); // Email получателя | |
$mail->isHTML(true); | |
$mail->Subject = $pagetitle; | |
$mail->Body = $textMessage; | |
$mail->AltBody = ''; | |
// Секретный ключ | |
$secret = "6Lc5IaAUAAAAABQU1CxOWxZLmqG-7C80Bp_VSzm3"; | |
// Пустой ответ каптчи | |
$response = null; | |
// Для проверка вашего секретного ключа | |
$reCaptcha = new ReCaptcha($secret); | |
// Валидация $_POST['name'] и $_POST['email'] (если нужна) | |
if ($_POST["g-recaptcha-response"]) { | |
$response = $reCaptcha->verifyResponse( | |
$_SERVER["REMOTE_ADDR"], | |
$_POST["g-recaptcha-response"] | |
); | |
} | |
// Отправка письма в случае успеха | |
if ($response != null && $response->success) { | |
$mail->send(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good evening. How can I link this form to the table that I want to send to the mail from the site page. I put all the files in the hosting, but I can’t link them. I’m not a programmer, I’m just building a site for myself, I ask for help. thanks in advance.