Bienvenido a datoweb.com!! En este foro podrás encontrar ayuda sobre diseño y desarrollo web en general. Si quieres formar parte de esta comunidad para pedir ayuda o colaborar ayudando a otros usuarios del foro solo tienes que registrarte desde el siguiente enlace: Registrarse en el Foro

Enviar correo mediante PHPMailer con php y 1and1

En este ejemplo vemos como enviar un correo mediante PHPMailer con php utilizando una cuenta de correo smtp de 1and1, antes de usar este código tienes que descargar la librería phpmailer desde este enlace PHPmailer e incluirla dentro del directorio web.

Ahora el código necesario para enviar un correo con PHPMailer y 1and1:
<?php

date_default_timezone_set('Europe/Lisbon');

require 'PHPMailer/class.phpmailer.php';
require 'PHPMailer/class.smtp.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSendMail(); //or $mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

$mail->Timeout=60;

$mail->Helo = "dominio.com"; //Muy importante para que llegue a hotmail y otros

//Set the hostname of the mail server
$mail->Host = 'smtp.1and1.es';

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 25;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "correo@envia.com";

//Password to use for SMTP authentication
$mail->Password = "*****";

//Set who the message is to be sent from
$mail->setFrom('correo@envia.com', 'Nombre');

//Set an alternative reply-to address
$mail->addReplyTo('correo@envia.com', 'Nombre');

//Set who the message is to be sent to
$mail->addAddress('correo@destino.com');

//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';

//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

$mail->Body = '<h1>This is a plain-text message body</h1> Lorem ipsum dolor sit amet, consectetur.';

$mail->IsHTML(true);

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}



?>
si de esta manera no funciona solo tienes que cambiar esto:
$mail->isSendMail(); //or $mail->isSMTP();
por esto:
$mail->isSMTP(); //or $mail->isSendMail();
salu2
Editado
1
Puntos
4492
Visitas
1
Resp
Por alber hace 77 meses
Administrador
Respuesta #1
si quiero lograr lo mismo pero desde otro proveedor de hosting : ¿solo debo cambiar 1and1.es por mihosting.com ? si tomamos como referencia este ejemplo
0
Puntos
Por claudioam hace 9 meses
Principiante
Compartir en facebook
Compartir en twitter
Compartir
Para comentar Inicia sesión o Registrate