-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
51 lines (43 loc) · 1.65 KB
/
contact.php
File metadata and controls
51 lines (43 loc) · 1.65 KB
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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php'; // Asegúrate de tener PHPMailer instalado
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$nombre = htmlspecialchars(trim($_POST["nombre"] ?? ''));
$apellido = htmlspecialchars(trim($_POST["apellido"] ?? ''));
$email = htmlspecialchars(trim($_POST["email"] ?? ''));
$mensaje = htmlspecialchars(trim($_POST["mensaje"] ?? ''));
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "⚠️ Correo inválido.";
exit;
}
$mail = new PHPMailer(true);
try {
// Configuración del servidor SMTP de Gmail
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mayorkingdesign@gmail.com';
$mail->Password = 'ihtvouxjhryomdxy'; // contraseña de aplicación sin espacios
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Remitente y destinatario
$mail->setFrom('mayorkingdesign@gmail.com', 'Mayorking Design');
$mail->addAddress('mayorkingdesign@gmail.com'); // Puedes cambiarlo si deseas
// Contenido
$mail->isHTML(false);
$mail->Subject = 'Nuevo mensaje desde MayorkingDesign.com';
$mail->Body = "Nombre: $nombre $apellido
Correo: $email
Mensaje:
$mensaje";
$mail->send();
echo "✅ Tu mensaje fue enviado correctamente. ¡Gracias por contactarnos, $nombre!";
} catch (Exception $e) {
echo "❌ Error al enviar el mensaje. Error: {$mail->ErrorInfo}";
}
} else {
http_response_code(405);
echo "Método no permitido";
}
?>