O
O
Olga2018-10-01 22:43:25
PHP
Olga, 2018-10-01 22:43:25

The application leaves the site via SMTP, but the letter does not arrive. Why?

Hello. The problem is this: I fill out an application on the site, it says that the application has been sent, but as a result it does not come. Here is the handler code:

<?php
// Файлы phpmailer
require_once ('PHPMailer.php');
require_once ('SMTP.php');
require_once ('Exception.php');
$mail = new PHPMailer\PHPMailer\PHPMailer();
// Переменные
$name = $_POST['name'];
$number = $_POST['phone'];
$email = $_POST['email'];
// Настройки
$mail->isSMTP(); 
$mail->Host = 'smtp.mail.ru'; 
$mail->SMTPAuth = true; 
$mail->Username = 'username; // Ваш логин 
$mail->Password = 'password'; // Ваш пароль
$mail->SMTPSecure = 'ssl'; 
$mail->Port = 465;
$mail->setFrom('username'); // Ваш Email
$mail->addAddress('username'); // Email получателя
// $mail->addAddress('[email protected]'); // Еще один email, если нужно.

// Прикрепление файлов
// $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
// $mail->addAttachment($_FILES['upload']['tmp_name'], $_FILES['upload']['name']);

 
// Письмо
$mail->isHTML(true); 
$mail->Subject = "Новая заявка на консультацию"; // Заголовок письма
$mail->Body = "Имя $name . Телефон $phone . Почта $email"; // Текст письма

js code:
$(document).ready(function() {

// Добавляем маску для поля с номера телефона
$('#phone').mask('+7 (999) 999-99-99');

  $( "form" ).submit( function() {
    if ( !this.checkValidity() )
      alert('Пожалуйста, заполните обязательные поля.');
    else  {
      $.ajax( {
        type: "POST",
        url: "/form/mail.php",
        data: $( this ).serialize()
      } ).done( function() {
        alert( "Заявка принята! В ближайшее время наш менеджер с Вами свяжется. js" );
      } );
    }
    return false;
  } );
} );

Form code:
<form class="row" id="form" name="contact" action="" method="POST" novalidate enctype="multipart/form-data">                
    <div class="inputwrap">
    <label for="name">Ваше имя<sup>*</sup></label>
    <input type="text" id="name" required="required" name="name" class="text-input" />
    </div>

    <div class="inputwrap">
    <label for="phone">Контактный телефон<sup>*</sup></label>
    <input id="phone" required type="text" name="phone" class="text-input" placeholder="+7 (800) 000-00-00" required />
    </div>
    
    <span class="result_message"></span>

    <div class="inputwrap checkwrap">
        <input type="checkbox" name="check_agreement" id="check_agreement" required>
        <label for="check_agreement">
            С <a target="_blank" href="/agreement.htm">условиями</a> обработки персональных данных ознакомлен
            </label>
    </div>
    
        <div class="inputwrap" style="float: right;">
        <input type="submit" name="submit" class="button" id="submit" value="Отправить">
    </div>

</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex-1917, 2018-10-02
@alex-1917

1. Accept on a box in Yandex, forget about Google boxes and mail-ru-boxes forever.
2. Use this https://github.com/Ipatov/SendMailSmtpClass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question