Para enviar correo electrónico con autenticación de SMTP en Windows Server bastará con copiar las librerías al directorio raíz del sitio web.
A continuación,ión les compartimos el script para el envío de correo y las librerías de PHPMailer.
<?php require 'phpmailer\PHPMailer.php'; require 'phpmailer\SMTP.php'; require 'phpmailer\Exception.php'; $mail = new PHPMailer\PHPMailer\PHPMailer(); $mail->IsSMTP(); // Set mailer to use SMTP //$mail->SMTPDebug = 3; $mail->Host = 'server-hostname'; // Specify main server name of your account $mail->Port = 587; // Set the SMTP port (25/587/465) $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'mail@domainname'; // SMTP username $mail->Password = '********'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted $mail->From = 'mail@domainname'; $mail->FromName = 'Your From name'; $mail->AddAddress('mail@yourdomainname', 'Name'); // Add a recipient $mail->IsHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } ?>
Para depurar los errores, puede des-comentar la línea $ mail-> SMTPDebug = 3;
* Nota esta configuración solo aplica para clientes que utilizan Cloud Servers o Bare Metal con Windows Server.
¿Le fue útil este artículo?
¡Qué bueno!
Gracias por sus comentarios
¡Sentimos mucho no haber sido de ayuda!
Gracias por sus comentarios
Comentarios enviados
Agradecemos su iniciativa, e intentaremos corregir el artículo