Receive form data with php on gmail account

0

I want to receive the data of this form to a gmail account through PHP. Currently if I send it I do not receive anything including the spam folder.

<form method="post" action="action.php">

        <label for="email" id="email">Email <span>*</span></label>
        <input type="email" id="" name="email">

         <div>
             <div>
                <label for="name" id="text">Nombre <span>*</span> </label>
                <input type="text" id="name" name="name">
             </div>
             <div>
                <label for="tlf-num">Teléfono <span>*</span> </label>
                <input id="tlf-num" type="text" name="tlf-num" >
            </div>
         </div>
        <div>
            <label for="message" id="#">Mensaje</label>
            <textarea contenteditable="false" name="message" id="message" cols="30" rows="10"></textarea>
        </div>
        <input type="submit" value="ENVIAR">
    </form>

This is the php code, this same code worked for me on another website about three years ago, so I'm confused about what may be happening.

<?php
if (isset($_POST['name']) && isset($_POST['email'])  && isset($_POST['tlf-num']) && isset($_POST['message']) != ""){

$nombre = $_POST['name'];
$mail = $_POST['email'];
$header = 'From: ' . $mail . " \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";
$mensaje = "Nombre " . $nombre . " ";
$mensaje .= "Su e-mail es: " . $mail . " \r\n";
$mensaje .= "Mensaje: " . $_POST['message'] . " \r\n";
$mensaje .= "Enviado el " . date('d/m/Y', time());
$para = '[email protected]';
$asunto = 'Formulario contacto Web';

mail($para, $asunto, utf8_decode($mensaje), $header);
echo "<script type='text/javascript'>
        setTimeout( function() {
          window.location.href='https://loquesea.com';
        }, 1500)
     </script>";
}
else{
    echo "<script type='text/javascript'>
        alert('Revisa los datos');
        window.location.href='https://loquesea.com';
     </script>";
}
?>

I add my php.ini file because as I have been reading the error it can be in the mail function of this file, I add it below as I have it.

[mail function]
; For Win32 only.
; http://php.net/smtp
; SMTP = localhost
; http://php.net/smtp-port
; smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path = "env -i /usr/sbin/sendmail -t -i"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on Windows).
;mail.log = syslog
    
asked by Juan 22.11.2017 в 23:18
source

1 answer

0

Try this:

try{ 
    mail($para, $asunto, utf8_decode($mensaje), $header);
}catch(Exception $e){
    echo $e->getMessage();
}

If there is no error in the exception, it is likely that if the email is being sent to spam or spam

    
answered by 23.11.2017 в 00:05