Página de formulario de contacto con PHP Mailer no se ejecuta
Publicado por Joaquin (1 intervención) el 09/04/2021 00:58:30
Soy nuevo en el mundo del desarrollo web y de a poco voy conociendo cosas. Escuche sobre PHP Mailer y lo quise implementar en mi proyecto, pero estoy teniendo problemas al querer entrar a la página de contacto donde implemente el PHP Mailer. Me aparece "Esta página no funciona en este momento. HTTP ERROR 500". Seguramente debo haber escrito algo mal en mi código porque no tengo idea de PHP. El código lo copie de un video. Lo raro es que hice todo exactamente igual y no me funciona. Ya probé en dos servidores con PHP y también en XAMPP y nada. No tengo dudas que hice algo mal. Acá les dejo el código. Gracias de antemano.
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
$result="";
if(isset($_POST['submit'])){
require 'php-mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mial->SMTPAuth=true;
$mial->SMTPSecure='tls';
$mial->Username='mi-email@gmail.com';
$mial->Password='contraseña'
$mail->setFrom($_POST['email'],$_POST['nombre']);
$mail->addAddress('mi-email@gmail.com');
$mial->addReplyTo($_POST['email'],$_POST['nombre']);
$mail->isHTML(true);
$mail->Subject='Enviado por'.$_POST['nombre'];
$mial->Body='<h1 aling=center>Nombre: '.$_POST['nombre']. '<br>Email: '.$_POST['email'.'<br>Mensaje: '.$_POST['mensaje'].'</h1>';
if(!$mail->send()){
$result="Algo esta mal. Intente de nuevo o mas tarde."
}
else
{
$result="Gracias. Estaremos respondiendo a la brevedad."
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>WEB</title>
<link rel="shortcut icon" href="" type="image/x-icon">
<link rel="apple-touch-icon" href="">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Link to your css file -->
<link rel="stylesheet">
<link rel="shortcut icon" href="" type="image/x-icon">
<link rel="apple-touch-icon">
<link rel="stylesheet" href="Bootstrap/css/bootstrap.min.css">
<!-- Link to your css file -->
<link rel="stylesheet" href="style.css">
<!-- Icons Bootstrap -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
<!-- Fonts Google -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,500;1,600&display=swap" rel="stylesheet">
</head>
<body>
<!-- Start coding here -->
<div class="container" id="form">
<h1 class="text-center mt-5">Contacto</h1>
<form action="" method="post">
<div class="form-group">
<label for="nombre">Nombre</label>
<input name="nombre" type="text" class="form-control" id="exampleFormControlInput1" placeholder="Nombre completo" required>
</div>
<div class="form-group">
<label for="email">Correo electrónico</label>
<input name="email" type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ejemplo@mail.com" required>
</div>
<div class="form-group">
<label for="mensaje">Mensaje</label>
<textarea name="mensaje" class="form-control" id="exampleFormControlTextarea1" placeholder="Escriba su mensaje aquí" rows="3" required></textarea>
</div>
<button type="submit" name="submit" class="btn btn-primary">Enviar</button>
<h5> <?= $result; ?></h5>
</form>
</div>
<!-- Coding End -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
Valora esta pregunta


0