<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/favicon.ico">
<title>Отправка формы на почту </title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<style>
form {
background-color: #f9f9f9;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4">
<form action="mail.php" method="POST">
<legend>Заголовок формы</legend>
<div class="form-group">
<label for="">Введите ваше имя</label>
<input type="text" class="form-control" id="" name="user_name" placeholder="Например, Иван">
</div>
<div class="form-group">
<label for="">Введите номер телефона</label>
<input type="text" class="form-control" id="" name="user_phone" placeholder="+7 (999) 99 99 999">
</div>
<div class="form-group">
<label for="">Введите email</label>
<input type="text" class="form-control" id="" name="user_email" placeholder="[email protected]">
</div>
<button type="submit" class="btn btn-primary">Отправить форму</button>
</form>
</div><!-- .col-sm-4 -->
</div> <!-- .row -->
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="http://getbootstrap.com/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
<?php
require_once('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->CharSet = 'utf-8';
$name = $_POST['user_name'];
$phone = $_POST['user_phone'];
$email = $_POST['user_email'];
$mail->isSMTP();
$mail->Host = 'smtp.yandex.ru';
$mail->Port = 25;
$mail->Username = '[email protected]';
$mail->Password = '';
$mail->addAddress('[email protected]');
$mail->isHTML(true);
$mail->SMTPSecure = 'ssl';
$mail->Subject = 'Заявка с тестового сайта';
$mail->Body = '' .$name . ' оставил заявку, его телефон ' .$phone. '<br>Почта этого пользователя: ' .$email;
$mail->AltBody = '';
$mail->SMTPDebug = 2;
$mail->setFrom('[email protected]', 'Сайт site.ru');
if(!$mail->send()) {
echo $mail->ErrorInfo;
} else {
header('location: thank-you.html');
}
?>
Ошибка: 2020-01-11 00:45:05 SMTP ERROR: Failed to connect to server: (0) 2020-01-11 00:45:05 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting