-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_mail.php
64 lines (54 loc) · 1.86 KB
/
send_mail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
ob_start();
error_reporting(E_ALL);
session_start();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
header("Location: index.php");
$contenido = '
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Nuevo Mensaje</title>
</head>
<body>
<p><strong>Nombre</strong>: '.$_POST["name"].'</p>
<p><strong>Apellidos</strong>: '.$_POST["surename"].'</p>
<p><strong>Usuario</strong>: '.$_POST["user"].'</p>
<p><strong>Correo Electrónico</strong>: '.$_POST["email"].'</p>
<p><strong>Teléfono</strong>: '.$_POST["phone_number"].'</p>
<p><strong>País</strong>: '.$_POST["country"].'</p>
<p><strong>Mensaje</strong>: '.$_POST["menssage"].'</p>
<p><strong>Política de Privacidad</strong>: '.$_POST["privacy_policy"].'</p>
</body>
</html>
';
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.###.###';
$mail->SMTPAuth = true;
$mail->Username = '###@###.###';
$mail->Password = '###';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->setFrom('###@###.###', 'alejandroalsa.es');
$mail->addAddress($_POST["email"], 'alejandroalsa.es');
$mail->isHTML(true);
$mail->Subject = 'Mensaje Recibido';
$mail->Body = $contenido;
$mail->CharSet = 'UTF-8';
$mail->send();
$_SESSION["flash"] = ["email" => "{$_POST['email']}"];
echo 'Mensaje Recibido';
ob_end_clean();
header("Location: index.php");
} catch (Exception $e) {
echo "No se pudo enviar el mensaje. Error de correo: {$mail->ErrorInfo}";
}