Привет всем гуру программирования :)
Суть: Есть форма с 4-мя input и одной textarea. На почту приходят только поля : Name, Email и Message. Поле с номером телефона приходит пустое.
Вроде написал код в PHP для отображения номера телефона, но не работает. Ошибся или ума не хватает.
Пишу на PhpStorm, локальный сервер - OpenServer. Отправляю письма через "smtp.gmail.com".
<form action="#" class="form-contact form-contact-dark" id="contactForm">
<div class="row">
<div class="col-sm-6 col-md-6">
<div class="form-group">
<input type="text" class="form-control" id="p_name" placeholder="Ваше имя" required="">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6 col-md-6">
<div class="form-group">
<input type="email" class="form-control" id="p_email" placeholder="Ваш Email" required="">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6 col-md-6">
<div class="form-group">
<input type="text" class="form-control" id="p_subject" placeholder="Тема письма">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6 col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="phone" id="phone" placeholder="Ваш номер телефона для связи" required="">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<textarea id="p_message" class="form-control" rows="6" placeholder="Напишите текст сообщения для заказа" maxlength="200" required=""></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group text-center">
<div id="success"></div>
<button type="submit" class="btn btn-primary">Отправить сообщение</button>
</div>
</form>
<?php
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
$errorMSG = "Name is required ";
} else {
$name = $_POST["name"];
}
// Phone
if (empty($_POST["phone"])) {
$errorMSG = "Phone is required ";
} else {
$phone = $_POST["phone"];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST["email"];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG .= "Message is required ";
} else {
$message = $_POST["message"];
}
/* Contact Form Setup Begin */
$send_name = "No Name"; // Replace your name
$send_title = "ZAKAZ"; // Replace email sent title
$send_address = "email@gmail.com"; // Replace your email address
$smtp_address = "email@gmail.com"; // Replace your email GMail address
$smtp_password = "password"; // Replace your email password
$smtp_server = "smtp.gmail.com"; // Replace your email server address
/* Contact Form Setup End */
date_default_timezone_set('Etc/UTC');
require '../inc/phpmailer/PHPMailerAutoload.php';
$mail = new phpmailer(true);
try{
// $mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = $smtp_server;
$mail->SMTPAuth = true;
$mail->Username = $smtp_address;
$mail->Password = $smtp_password;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Recipients
$mail->setFrom($smtp_address, $send_title);
$mail->addAddress($send_address);
$mail->addReplyTo($send_address);
// Content
$mail->isHTML(true);
$mail->Subject = $send_title;
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "<br>";
$Body .= "Email: ";
$Body .= $email;
$Body .= "<br>";
$Body .= "Message: ";
$Body .= $message;
$Body .= "<br>";
$Body .= "Phone: ";
$Body .= $phone;
$mail->Body = $Body;
$mail->send();
echo 'Message has been send!';
} catch (Exception $e){
// echo 'Message could not be send. Error: ', $mail->ErrorInfo;
echo 'Message could not be send. Error: ';
}
?>
Итог: