<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require "./PHPMailer/src/PHPMailer.php";
require "./PHPMailer/src/Exception.php";
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
$mail->IsHTML(true);
// send to
$mail->addAddress("mail@mail.mail");
$theme = '[ЗАЯВКА НА ТРЕНИНГ]';
$mail->Subject = $theme;
// letter's body
$body = '<h1>Данные заявки</h1>';
$name = $_POST["name"];
$tel = $_POST["tel"];
$email = $_POST["email"];
if(trim(!empty($name))){
$body.='<p><strong>Имя:</strong> '.$name.'</p>';
}
if(trim(!empty($tel))){
$body.='<p><strong>Телефон:</strong> '.$tel.'</p>';
}
if(trim(!empty($email))){
$body.='<p><strong>From:</strong> '.$email.'</p>';
}
$mail->Body = $body;
// send
if(!$mail->send()) {
$message = 'Ошибка';
} else {
$message = 'Данные не отправлены!';
}
$response = ['message' => $message];
header('Content-type: application/json');
echo json_encode($response);
?>
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'user@example.com'; //SMTP username
$mail->Password = 'secret'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`