简体   繁体   中英

Contact form sending emails without name, email and message

I have a problem with a contact form I'm building because it sends the message without sender info (name & email) and no message as well. And I need that. I tried the var_dump from another post I found but did not work.

HTML

<form action="form_process.php" class="contact_form" method= "post" onsubmit>
<ul>
 <li><label for="name">name:</label><input type="text" required /></li>
<li><label for="email">email:</label><input type="email" name="email" required /></li>
<li><label for="message">message:</label><textarea name="message" cols="40" rows="6" required ></textarea></li>
<li><button class="submit" type="submit">Enviar</button></li>
</ul>
</form>
</div>

PHP

<?php

$name = var_dump($_POST['name']);
$email = var_dump($_POST['email']);
$message = var_dump($_POST['message']);
$to = "mmechenique@gmail.com";
$subject = "Nuevo mensaje formulario de contacto";

mail ($to, $subject, $message, "From: " . $name);
echo "Tu mensaje ha sido enviado, muchas gracias!";

?>

Try using your form this way:

<form action="form_process.php" class="contact_form" method= "post">
<ul>
 <li><label for="name">name:</label><input type="text" name="name" required /></li>
<li><label for="email">email:</label><input type="email" name="email" required /></li>
<li><label for="message">message:</label><textarea name="message" cols="40" rows="6" required ></textarea></li>
<li><button class="submit" type="submit">Enviar</button></li>
</ul>
</form>
</div>

PHP:

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $to = "mmechenique@gmail.com";
    $subject = "Nuevo mensaje formulario de contacto";

    mail ($to, $subject, $message, "From: " . $name);
    echo "Tu mensaje ha sido enviado, muchas gracias!";

  ?>

Your HTML should look like:

<form action="form_process.php" class="contact_form" method="post">
    <ul>
        <li>
            <label for="name">name:</label>
            <input type="text" name="name" required />
        </li>
        <li>
            <label for="email">email:</label>
            <input type="email" name="email" required />
        </li>
        <li>
            <label for="message">message:</label>
            <textarea name="message" cols="40" rows="6" required ></textarea>
        </li>
        <li>
            <button class="submit" type="submit">Enviar</button>
        </li>
    </ul>
</form>

Your PHP should look like:

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $to = "mmechenique@gmail.com";
    $subject = "Nuevo mensaje formulario de contacto";
    $headers  = "From: Enter something here < email@mail.com >\r\n";
    $headers .= "X-Sender: Enter something here < email@mail.com >\r\n";
    $headers .= 'X-Mailer: PHP/' . phpversion();
    $headers .= "X-Priority: 1\r\n"; // Urgent message!
    $headers .= "Return-Path: email@mail.com\r\n"; // Return path for errors
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";

    mail ($to, $subject, $message, $headers);
    echo "Tu mensaje ha sido enviado, muchas gracias!";

?>

I shouldn't be giving out the answer so easily because you should have done your research before posting your question but what the hell. Now you know for next time to do SOME research before posting your question.

EDIT:

<?php
    $headers  = "From: Enter your name < myemail@mail.com >\n"; //If you are the one sending the email enter your name here
    OR
    $headers  = "From: ".$name." < ".$email." >\n"; // If you are the one the email is being sent to then try this header

    $headers .= "X-Sender: Enter your name < myemail@mail.com >\n"; //Same logic applies for this guy
    OR
    $headers .= "X-Sender: ".$name." < ".$email." >\n"; //Same logic applies for this guy
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM