Yesterday I asked a question in which I sent an email with the PHPMailer function but I sent it blank. Today I try to send it and it arrives in my inbox but the problem is that it arrives as if I sent it to me, it is not taking into account the FROM data. Help please the code is as follows:
<?php
require_once('class.phpmailer.php');
require_once('class.smtp.php');
//require_once('PHPMailerAutoload.php');
require('vistas/mail.view.php');
define("destino", "[email protected]");
define("farmacia", "Guillermo");
if ($_SERVER['REQUEST_METHOD'] =='POST') {
$nombre=filter_var($_POST['nombre'], FILTER_SANITIZE_STRING);
$de=filter_var($_POST['de'], FILTER_SANITIZE_EMAIL);
$telefono=filter_var($_POST['telefono'], FILTER_SANITIZE_STRING);
$asunto=filter_var($_POST['asunto'], FILTER_SANITIZE_STRING);
$mensaje='
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>Cuerpo del mensaje</h1>
</body>
</html>
';
$mensaje.=filter_var($_POST['mensaje'], FILTER_SANITIZE_STRING);
$correo = new PHPMailer(); //Creamos una instancia en lugar usar mail()
$correo->IsSMTP();
$correo->SMTPOptions = array('ssl' => array('verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true));
// optional
// used only when SMTP requires authentication
$correo->SMTPAuth = true;
$correo->SMTPSecure = 'tls';
$correo->Host = "smtp.gmail.com";
$correo->Port = 587;
$correo->Username = '[email protected]';
$correo->Password = 'password';
//Usamos el SetFrom para decirle al script quien envia el correo
$correo->SetFrom($de, $nombre);
//Usamos el AddReplyTo para decirle al script a quien tiene que responder el correo
$correo->AddReplyTo($de, $nombre);
//Usamos el AddAddress para agregar un destinatario
$correo->AddAddress(destino, farmacia);
//Ponemos el asunto del mensaje
$correo->Subject = $asunto;
/*
* Si deseamos enviar un correo con formato HTML utilizaremos MsgHTML:
* $correo->MsgHTML("<strong>Mi Mensaje en HTML</strong>");
* Si deseamos enviarlo en texto plano, haremos lo siguiente:
* $correo->IsHTML(false);
* $correo->Body = "Mi mensaje en Texto Plano";
*/
$correo->MsgHTML($mensaje);
//Si deseamos agregar un archivo adjunto utilizamos AddAttachment
//$correo->AddAttachment("images/phpmailer.gif");
$correo->CharSet = "UTF8";
//$correo->Encoding = "quotedprintable";
//Enviamos el correo
if(!$correo->Send()) {
echo "Hubo un error: " . $correo->ErrorInfo;
} else {
echo "Mensaje enviado con exito.";
}
}
?>