A
A
Alexey Ivanov2016-12-30 09:32:29
SMTP
Alexey Ivanov, 2016-12-30 09:32:29

How to send a letter from the site via smtp.mail.ru?

Hello!
I'm trying to set up sending a letter from the hosting using phpmailer to smtp.mail.ru. Everything was prescribed, guided by a popular lesson. And it doesn’t work, even if you crack! Gives the following error:
2016-12-30 06:09:15 CLIENT -> SERVER: EHLO alexxx6c.bget.ru 2016-12-30 06:09:15 SMTP ERROR: EHLO command failed: 2016-12-30 06:09 :15 SMTP NOTICE: EOF caught while checking if connected SMTP connect() failed. The letter could not be sent. Error: SMTP connect() failed
Here is the script code itself:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

//require 'phpmailer/PHPMailer.php';
require 'phpmailer/PHPMailerAutoload.php';

if (!empty($_POST['name'])) {

    $mail = new PHPMailer;
    $mail->isSMTP();

    $mail->SMTPDebug = 1;

    $mail->Host = 'smtp.mail.ru';

    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]'; // логин от вашей почты
    $mail->Password = '******'; // пароль от почтового ящика
    $mail->SMTPSecure = 'SSL';
    $mail->Port = '465';

    $mail->CharSet = 'UTF-8';
    $mail->From = '[email protected]';  // адрес почты, с которой идет отправка
    $mail->FromName = 'Алексей'; // имя отправителя
    $mail->addAddress('[email protected]', 'Alexey');

    $mail->isHTML(true);

    $mail->Subject = $_POST['subject'];
    $mail->Body = "Имя: {$_POST['name']}<br> Email: {$_POST['email']}<br> Сообщение: " . nl2br($_POST['body']);
    $mail->AltBody = "Имя: {$_POST['name']}\r\n Email: {$_POST['email']}\r\n Сообщение: {$_POST['body']}";

    //$mail->SMTPDebug = 1;

    if ($mail->send()) {
        $answer = '1';
    } else {
        $answer = '0';
        echo 'Письмо не может быть отправлено. ';
        echo 'Ошибка: ' . $mail->ErrorInfo;
    }
    die($answer);
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Форма обратной связи!!!</title>
</head>
<body>

<form action="" method="post" id="contact">
    <p>
        <label for="name">Имя</label>
        <input type="text" name="name" id="name"><span></span>
    </p>
    <p>
        <label for="subject">Тема</label>
        <input type="text" name="subject" id="subject"><span></span>
    </p>
    <p>
        <label for="email">Email</label>
        <input type="text" name="email" id="email"><span></span>
    </p>
    <p>
        <label for="body">Сообщение</label>
        <textarea name="body" cols="30" rows="10" id="body"></textarea><span></span>
    </p>
    <p>
        <input id="submit" type="submit" name="submit" value="Отправить"><span></span>
    </p>
</form>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<!--script>
$(function(){

  $('#contact').submit(function(){
    var errors = false;
    $(this).find('span').empty();

    $(this).find('input, textarea').each(function(){
      if( $.trim( $(this).val() ) == '' ) {
        errors = true;
        $(this).next().text( 'Не заполнено поле ' + $(this).prev().text() );
      }
    });

    if( !errors ){
      var data = $('#contact').serialize();
      $.ajax({
        url: 'index.php',
        type: 'POST',
        data: data,
        beforeSend: function(){
          $('#submit').next().text('Отправляю...');
        },
        success: function(res){
          if( res == 1 ){
            $('#contact').find('input:not(#submit), textarea').val('');
            $('#submit').next().empty();
            alert('Письмо отправлено');
          }else{
            $('#submit').next().empty();
            console.log('Ошибка отправки');
          }
        },
        error: function(){
          console.log('Ошибка!');
        }
      });
    }

    return false;
  });

});

</script-->

</body>
</html>

I temporarily disabled the jquery script for ajax to read errors, but this does not matter.
Of course, I checked the login and password for authentication in mail.ru a thousand times.
Tell me, please, what is my mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ivanov, 2016-12-30
@mg15

Problem solved.
It turned out that the correct line would be:$mail->Host = 'smtp.mail.ru';
$mail->Host = 'ssl://smtp.mail.ru';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question