Enviar Correo con PHP y PHPmailer

vamos a user PHPmailer, descargar desde :

http://sourceforge.net/projects/phpmailer/

necesitaremos :

class.phpmailer.php
class.smtp.php


entonces el codigo asi de simple :




<?php
include("class.phpmailer.php");
include("class.smtp.php");
error_reporting(0);

$cuerpo_correo = "<br/><br/><br/><br/> <div style='color: rgb(176, 173, 173); font-family: verdana,geneva,sans-serif;'><font size='2'> Le pongo color y tipo de letra solo para el ejemplo</span></font></div>";
$mail = new phpmailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = false; // enable SMTP authentication
$mail->Host = "mail.gmail.com"; // sets GMAIL as the SMTP server
$mail->Username = "usuario";
$mail->FromName = "usuario";
$mail->From = "tusuario@gmail.com";
$mail->Timeout=30;
$mail->AddAddress("destinatario@gmail.com");
$mail->AddBCC("copiaoculta@gmail.com");
$mail->IsHTML(true);
$mail->Subject = "Asunto";
$mail->Body = $cuerpo_correo;
$mail->AltBody = "MIEMPRESA";
$exito = $mail->Send();
$intentos=1;
 while ((!$exito) && ($intentos < 2)) {
sleep(5);
$exito = $mail->Send();
$intentos=$intentos+1;

  }
if(!$exito){
echo "Problemas enviando correo electrónico   ".$valor;
echo "<br/>".$mail->ErrorInfo;
}
else{
echo "<h1>Mensaje enviado correctamente</h1>";
echo "<h5>Direccion :". $_SESSION["correo"] ."</h5>";
echo "<meta http-equiv='refresh' content='4; URL=index.php'>";
}

?>

----------------------------------------------------------------------------------------------
hey! si te he ayudado compartelo! o deja un comentario si podemos mejorar el código. 
if I have helped you share it! or leave a comment if we can improve the code.

No hay comentarios:

Publicar un comentario

Todos los comentarios son bien recibidos...

CommentFB