Form does not send emails

0

I created a blog with html5, css3 and php. In the contact page php I have put a form so that you can send me an email with a comment, but I have done some test and I do not receive anything. I have put two lines to show me if there are errors in the php and it does not tell me that there is anything wrong. This is the code:

<?php
    require_once('../includes/config.php');
    if(!$user->is_logged_in()){
        header('Location:login.php');
    }
    if(isset($_GET['delpost'])){
        $stmt=$db->prepare('DELETE FROM blog_posts WHERE postID=:postID');
        $stmt->execute(array(':postID'=>$_GET['delpost']));
        header('Location:index.php?action=deleted');
        exit;
    }
?>
<!DOCTYPE html>
<html lang="es-ES">
<head>
    <meta charset="utf-8">
    <title>Contacto</title>
    <link rel="stylesheet" href="../style/styles.css">
    <style>
        #seccion{
            background-color:#9BE8FF;
        }
        #seccion>p>a{
            font-size:20px;
        }
    </style>
</head>
<body>
    <header>
        <h1>REAL ZARAGOZA</h1>
        <h3>... MÁS QUE UNA PASIÓN!</h3>
    </header>
    <nav>
        <ul>
            <li><a href="../index.php">Blog</a></li>
            <li><a href="../about.php">Sobre nosotros</a></li>
            <li><a href="../fotos.php">Fotos</a></li>
            <li><a href="contacto.php">Contacto</a></li>
            <li><a href="#">Suscribete</a></li>
        </ul>
    </nav>
    <main>
        <aside>
            <h1>ENLACES DE INTERES</h1>
            <a href="http://realzaragoza.com">Página oficial del Real Zaragoza</a></br>
            <a href="http://aupazaragoza.com">Página de Aupa Zaragoza</a></br>
            <a href="https://twitter.com/realzaragoza">Real Zaragoza en Twitter</a></br>
            <a href="https://es-es.facebook.com/RealZaragozaOficial">Real Zaragoza en Facebook</a></br>
            <a href="https://instagram.com/realzaragoza">Real Zaragoza en Instagram</a></br>
            <a href="https://heraldo.es/noticias/deportes/futbol/real_zaragoza/portada">Heraldo de Aragón</a></br>
            <a href="http://elperiodicodearagon.com/noticias/realzaragoza">El Periódico de Aragón</a></br>
            <h1>PATROCINADORES</h1>
            <a align="middle" class="foto" href="https://adidas.es" target="_blank"><img src="../images/adidas.png" alt="ADIDAS" border="0"></a></br>
            <a align="middle" class="foto" href="https://jamoneseutiquio.com" target="_blank"><img src="../images/eutiquio.jpg" alt="JAMONES EUTIQUIO" border="0"></a></br>
            <a align="middle" class="foto" href="https://caixabank.es/particular/home/particulares_es.html" target="_blank"><img src="../images/caixabank.jpg" alt="CAIXABANK" border="0"></a></br>
            <a align="middle" class="foto" href="https://movistar.es" target="_blank"><img src="../images/movistar.jpg" alt="MOVISTAR" border="0"></a></br>
        </aside>
        <section id="seccion">
            <?php include('menu.php');?>
            <form id="ContactForm" method="post" action="">
                <p><label>Nombre: </label><br/>
                <input type="text" name="nombre" value=""></p>
                <p><label>Email: </label><br/>
                <input type="text" name ="email" value=""></p>
                <p><label>Asunto: </label><br/>
                <input type="text" name="asunto" value=""></p>
                <p><label>Mensaje: </label><br/>
                <textarea name="mensaje" cols="60" rows="10"></textarea></p>
                <p><input type="submit" name='submit' value="Enviar"></p>  
            </form>
            <?php
                error_reporting(E_ALL);
                ini_set('display_errors', '1');
                if(isset($_POST["nombre"]) and isset($_POST["correo"])){
                    $destino="[email protected]";
                    $asunto="Real Zaragoza";
                    $nombre=$_POST['nombre'];
                    $email=$_POST['email'];
                    $asunto=$_POST['asunto'];
                    $mensaje=$_POST['mensaje'];
                    $msn="
                        Nombre: $nombre \n
                        email: $email \n
                        asunto: $asunto \n
                        mensaje: $mensaje \n
                    ";
                    $cabeceras='From: [email protected]'."\r\n".'Reply-To: [email protected]'."\r\n".'X-Mailer: PHP/'.phpversion();
                    if(mail($destino,$asunto,$msn,$cabeceras)){
                        header("Location:contacto.php?m=1");
                        //echo "SE envio";
                    }
                }
            ?>
        </section>
    </main>
    <footer>
        <p>© 2018 Charly Utrilla</p>
    </footer>
</body>
</html>
    
asked by Charly Utrilla 07.09.2018 в 11:56
source

2 answers

2

Notice that you have an error in the first "if":

if(isset($_POST["nombre"]) and isset($_POST["correo"])){

It should be:

if(isset($_POST["nombre"]) and isset($_POST["email"])){
    
answered by 07.09.2018 / 14:31
source
0

I have already fixed it. In addition to having some parts of the code wrong, I did not have Mercury properly configured, nor did the php.ini file. Now it works well for me. Thanks to everyone.

P. D .: if someone else needs it on this page, it's all very detailed of what and how to do to send emails from localhost to an external email address (gmail) with smtp: link

    
answered by 08.09.2018 в 12:11