-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.php
More file actions
67 lines (55 loc) · 2.39 KB
/
send.php
File metadata and controls
67 lines (55 loc) · 2.39 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace PHPMailer\PHPMailer;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'assets/php/src/Exception.php';
require 'assets/php/src/PHPMailer.php';
require 'assets/php/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$nombre = trim($_POST['name']);
$apellido = trim($_POST['apellido']);
$email = trim($_POST['correo']);
$marca = trim($_POST['marca']);
$modelo = trim($_POST['modelo']);
$year = trim($_POST['year']);
$mensaje = trim($_POST['mensaje']);
if ($nombre == "" || $apellido == "" || $email == "" || $mensaje == "") {
//echo '<div class="alert alert-danger">Todos los campos son requeridos para el envio</div>';
echo 'Error: Todos los campos requeridos deben ser completados';
exit;
}
try {
// Configuración, cambiar correo y credenciales.
$mail->isSMTP();
$mail->Host = 'smtp.hostinger.com';
$mail->SMTPAuth = true;
$mail->Username = 'demo@allgarage.cl';
$mail->Password = 'Allgarage_Demo2025';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$to = "contacto@allgarage.cl"; // el correo donde llegará todo
$mail->setFrom('demo@allgarage.cl', 'Formulario Web Allgarage');
$mail->addReplyTo($email, $nombre . ' ' . $apellido); // Responder a este correo
$mail->addAddress($to);
$mail->addCC('denisse.rossel@todosuministros.cl'); // Copia a la dirección del remitente
$mail->addCC('efigueroa@allgarage.cl'); // Copia a la dirección del remitente
$mail->Subject = 'Nuevo mensaje desde tu web';
$mail->isHTML(true);
$mail->Subject = 'Nuevo mensaje desde Allgarage.cl';
$mail->Body = "
<strong> $nombre $apellido </strong> te ha contactado desde tu web y ha enviado la siguiente información: <br>
<p> <strong> Marca: </strong> $marca <br>
<strong> Modelo: </strong> $modelo <br>
<strong> Año: </strong> $year <br>
<strong> Mensaje: </strong> $mensaje </p> ";
// Envío del correo electrónico
$mail->send();
echo "Formulario enviado correctamente";
} catch (Exception $e) {
echo "Error al enviar el formualrio: " . $mail->ErrorInfo;
}
?>