PHP Mailer | The emails do not arrive and a strange message comes out when sending

0

I have a problem several days ago and I am not finding a solution anywhere, first try with php mail, and it did not work for me and they recommended me to use php mailer, but in the same way I think that the secure mail server does not work or nose that happens .., I get the message is sent and a strange message comes out, my code is as follows. HTML form:

<!DOCTYPE html>
<html>
<head>
    <title>FORMULARIO</title>
</head>
<body>
    <form action="PHPMailer-master/enviarmail.php" method="post">
        <h3>Nombre</h3>
        <input type="text" name="nombre">
        <h3>Apellido</h3>
        <input type="text" name="apellido">
        <h3>Mensaje</h3>
        <textarea name="mensaje"></textarea>
        Enviar
        <input type="submit" value="Enviar">
    </form>

</body>
</html>

Php code:

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader

require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

$mail = new PHPMailer(true);                              // Passing 'true' enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();   
                                       // Set mailer to use SMTP
    $mail->Host = 'single-priva4.privatednsorg.com:465';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'Juanse123.';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, 'ssl' also accepted
    $mail->Port = 465;                                    // TCP port to connect to


   $nombre=$_POST['nombre'];
   $apellido=$_POST['apellido'];
   $mensaje=$_POST['mensaje'];

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'CURSO';
    $mail->Body    = 'NOMBRE: ' . $nombre . "<br>Apellido: " . $apellido . "<br>Mensaje: " . $mensaje ;
    $mail->AltBody = 'Ejemplo de BODY 2';

    $mail->send();

    echo 'Mensaje enviado';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

?>

When I run on my hosting, I get sent message and this message:

2018-08-16 15:18:56 SERVER -> CLIENT: 220-single-priva4.privatednsorg.com ESMTP Exim 4.91 #1 Thu, 16 Aug 2018 11:18:56 -0400 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2018-08-16 15:18:56 CLIENT -> SERVER: EHLO www.cygnus.com.py
2018-08-16 15:18:56 SERVER -> CLIENT: 250-single-priva4.privatednsorg.com Hello www.cygnus.com.py [65.60.62.226]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250 HELP
2018-08-16 15:18:56 CLIENT -> SERVER: AUTH LOGIN
2018-08-16 15:18:56 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-08-16 15:18:56 CLIENT -> SERVER: <credentials hidden>
2018-08-16 15:18:56 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2018-08-16 15:18:56 CLIENT -> SERVER: <credentials hidden>
2018-08-16 15:18:56 SERVER -> CLIENT: 235 Authentication succeeded
2018-08-16 15:18:56 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2018-08-16 15:18:56 SERVER -> CLIENT: 250 OK
2018-08-16 15:18:56 CLIENT -> SERVER: RCPT TO:<[email protected]>
2018-08-16 15:18:56 SERVER -> CLIENT: 250 Accepted
2018-08-16 15:18:56 CLIENT -> SERVER: DATA
2018-08-16 15:18:56 SERVER -> CLIENT: 354 Enter message, ending with "." on a line by itself
2018-08-16 15:18:56 CLIENT -> SERVER: Date: Thu, 16 Aug 2018 11:18:56 -0400
2018-08-16 15:18:56 CLIENT -> SERVER: To: Juan Portillo <[email protected]>
2018-08-16 15:18:56 CLIENT -> SERVER: From: Juan <[email protected]>
2018-08-16 15:18:56 CLIENT -> SERVER: Subject: CURSO
2018-08-16 15:18:56 CLIENT -> SERVER: Message-ID: <[email protected]>
2018-08-16 15:18:56 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
2018-08-16 15:18:56 CLIENT -> SERVER: MIME-Version: 1.0
2018-08-16 15:18:56 CLIENT -> SERVER: Content-Type: multipart/alternative;
2018-08-16 15:18:56 CLIENT -> SERVER: boundary="b1_DESKyjWHbKeCItedA7v19pxw5c4LEPadZQO26CnMQ"
2018-08-16 15:18:56 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2018-08-16 15:18:56 CLIENT -> SERVER: 
2018-08-16 15:18:56 CLIENT -> SERVER: This is a multi-part message in MIME format.
2018-08-16 15:18:56 CLIENT -> SERVER: --b1_DESKyjWHbKeCItedA7v19pxw5c4LEPadZQO26CnMQ
2018-08-16 15:18:56 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2018-08-16 15:18:56 CLIENT -> SERVER: 
2018-08-16 15:18:56 CLIENT -> SERVER: Ejemplo de BODY 2
2018-08-16 15:18:56 CLIENT -> SERVER: 
2018-08-16 15:18:56 CLIENT -> SERVER: --b1_DESKyjWHbKeCItedA7v19pxw5c4LEPadZQO26CnMQ
2018-08-16 15:18:56 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2018-08-16 15:18:56 CLIENT -> SERVER: 
2018-08-16 15:18:56 CLIENT -> SERVER: NOMBRE: Juan <br>Apellido: Portillo<br>Mensaje: ghdfhgfgfj
2018-08-16 15:18:56 CLIENT -> SERVER: 
2018-08-16 15:18:56 CLIENT -> SERVER: 
2018-08-16 15:18:56 CLIENT -> SERVER: --b1_DESKyjWHbKeCItedA7v19pxw5c4LEPadZQO26CnMQ--
2018-08-16 15:18:56 CLIENT -> SERVER: 
2018-08-16 15:18:56 CLIENT -> SERVER: .
2018-08-16 15:18:57 SERVER -> CLIENT: 250 OK id=1fqK36-00FSCv-FF
2018-08-16 15:18:57 CLIENT -> SERVER: QUIT
2018-08-16 15:18:57 SERVER -> CLIENT: 221 single-priva4.privatednsorg.com closing connection
Mensaje enviado
    
asked by Juanse Portillo 16.08.2018 в 17:39
source

1 answer

0

It seems that you are enabling the debug. Try commenting on this line:

$mail->SMTPDebug = 2;

like this:

//$mail->SMTPDebug = 2;

The 'weird' thing you're seeing is the communications (SMTP protocol) between your client and the SMTP server.

Here you have more information about it if you are interested in the subject. Inside you will also find a simple example of sending e-mail, which I reproduce here below:

C = Customer; S = Server

S: 220 Servidor SMTP
C: HELO miequipo.midominio.com
S: 250 Hello, please to meet you
C: MAIL FROM: <[email protected]>
S: 250 Ok
C: RCPT TO: <[email protected]>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: Subject: Campo de asunto
C: From: [email protected]
C: To: [email protected]
C:
C: Hola,
C: Esto es una prueba.
C: Hasta luego.
C:
C: .
C: <CR><LF>.<CR><LF>
S: 250 Ok: queued as 12345
C: quit
S: 221 Bye

As you can see, it has a structure similar to the one you are finding. But that is something that must happen 'internally', it is not something that the user should see. If you see it, it is because you must be attaching a copy of all the documentation as the body of the message due to the debug option.

In short, try removing the debug option.

    
answered by 16.08.2018 в 17:43