How to send the data of a form to GMAIL with PHP

0

I need to know how I can send the values that the user completes in a contact form, via PHP to an email

    
asked by Jose011 29.08.2018 в 18:32
source

1 answer

1

I think this may be your solution:

First of all, you will need a form, for example this, that you can have in your file "contacto.html" (For example)

<form method="POST" action="enviar.php">
    <input type="text" name="nombre" placeholder="Nombre">
    <input type="text" name="email" placeholder="Email">
    <input type="text" name="telefono" placeholder="Telefono">
    <textarea name="Mensaje" placeholder="Tu mensaje aqui"></textarea>
    <input type="submit" name="submit" value="Enviar">
</form>

Now in the same folder, create a file called: send.php (as we have called in the action of the form) that contains this data:

<?php

// Declaración de variables del formulario
$nombre = $_POST['Nombre'];
$email = $_POST['Email'];
$telefono = $_POST['Telefono'];
$mensaje = $_POST['Mensaje'];

// Datos del email
$para = $email;
$titulo = 'S&S Solicitud de presupuesto';
$header = 'From: ' . $email;
$msjCorreo = "Nombre: $nombre\n Telefono: $telefono\n E-Mail: $email\n Mensaje:\n $mensaje";

if ($_POST['submit']) {

    if (mail($para, $titulo, $msjCorreo, $header)) {

    echo "<script language='javascript'>
    alert('Mensaje enviado, muchas gracias por contactar con nosotros.');
    </script>";
    } else {
        echo 'Falló el envio';
    }
}

?>

In $ for, you can put your email like this:

$ for = '[email protected]';

Or leave the email variable, so that the user gets a copy.

    
answered by 29.08.2018 в 18:51