<?php
require __DIR__ . "/functions.php";
if (isset($_POST["submit"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
// $errors = validation($_POST);
if (empty($errors)) {
send($name, $email, $subject, $message);
}
}
?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require __DIR__ . "/libs/PHPMailer/Exception.php";
require __DIR__ . "/libs/PHPMailer/PHPMailer.php";
require __DIR__ . "/libs/PHPMailer/SMTP.php";
function validation($data)
{
$errors = [];
if (empty($data["name"])) {
$errors["name"] = "erros";
}
if (empty($data["email"])) {
$errors["email"] = "erros";
}
if (empty($data["subject"])) {
$errors["subject"] = "erros";
}
if (empty($data["message"])) {
$errors["message"] = "erros";
}
return $errors;
}
function send($name, $email, $subject, $message)
{
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = "smtp.mail.ru";
$mail->SMTPAuth = true;
$mail->Username = "phpshulyak@mail.ru";
$mail->Password = "ЗАМАЗАНО";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->setFrom("phpshulyak@mail.ru", 'Small Apps');
$mail->addAddress("phpshulyak@mail.ru", 'Mikhail Protasevich');
$mail->isHTML(true);
$mail->Subject = "Small Apps: $subject";
$mail->Body = "Name: $name<br>E-mail: $email<br>Message: $message";
try {
$mail->send();
?>
<div class="success" >
Message sent
</div>
<?php
} catch (Exception $exception) {
?>
<div>
<?= $exception->getMessage() ?>
</div>
<?php
}
}
?>