Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('class.phpmailer.php');
- require_once('class.smtp.php');
- require_once('PHPMailerAutoload.php');
- require('vistas/mail.view.php');
- define("destino", "correo@gmail.com");
- 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>
- <table border="1">
- <tr>
- <td>Uno</td>
- <td>Dos</td>
- </tr>
- </table>
- </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 = 'correo@gmail.com';
- $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.";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement