send mail with test mail server tool

2

I need to enable the sending of mails by form. It is the first time I do it. I am based on this link:
link
I installed the mail server test tool to simulate a mail server:
link
With this, what I do is not send an email but "falsify" a shipment. By this I mean that the mail does not actually reach the recipient, but rather reaches a folder of the test mail server tool.
I have also configured the php.ini file of XAMPP to work with test mail server according to:
link

My code is very simple:

<?php
$mensaje = "Esto es una prueba";

if (mail('postmaster@localhost', 'prueba envio correo', $mensaje)) {
echo "email enviado con éxito";
} else{
echo "fallo de envío";
}
?>

When I run it, a success message appears, but nothing comes to the mail server test folder, so I need to know if the code works and why nothing comes to the folder.

    
asked by virtual8870 16.02.2017 в 17:31
source

1 answer

1

For sending emails you can occupy a library called PHPMailer . Code example:

require("class.phpmailer.php");
$mail = new PHPMailer();

//Luego tenemos que iniciar la validación por SMTP:
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = ""; // A RELLENAR. Aquí pondremos el SMTP a utilizar. Por ej. mail.midominio.com
$mail->Username = ""; // A RELLENAR. Email de la cuenta de correo. [email protected] La cuenta de correo debe ser creada previamente. 
$mail->Password = ""; // A RELLENAR. Aqui pondremos la contraseña de la cuenta de correo
$mail->Port = 465; // Puerto de conexión al servidor de envio. 
$mail->From = ""; // A RELLENARDesde donde enviamos (Para mostrar). Puede ser el mismo que el email creado previamente.
$mail->FromName = ""; //A RELLENAR Nombre a mostrar del remitente. 
$mail->AddAddress("correo"); // Esta es la dirección a donde enviamos 
$mail->IsHTML(true); // El correo se envía como HTML 
$mail->Subject = “Titulo”; // Este es el titulo del email. 
$body = “Hola mundo. Esta es la primer línea ”; 
$body .= “Aquí continuamos el mensaje”;
$mail->Body = $body; // Mensaje a enviar. 
$exito = $mail->Send(); // Envía el correo.

if ($exito) { 
   echo ‘El correo fue enviado correctamente.’; 
} else { 
   echo ‘Hubo un problema. Contacta a un administrador.’; 
} 
    
answered by 16.03.2017 в 04:14