简体   繁体   中英

HTML+PHP form not sending to my email

Lots of similar questions have been asked, but couldn't find an answer to the exact problem I have. I have a form that works completely fine, but I asked someone to design it nicer (which he did) and now it just doesn't work anymore. I don't know what's causing it.

I'm assuming there is something wrong in my HTML code for the form, since the .php page works perfectly fine (I copy/pasted it entirely) on my previous page.

Any idea?

<form name="htmlform" method="post" action="html_form_send.php">
<div class="row has-form">
    <div class="col-xs-12 col-sm-8 col-sm-offset-2">
            <div class="form-group">
                <label for="first_name" class="col-sm-3 control-label">Prénom *</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="first_name">
                    </div>
            </div>

            <div class="form-group">
                <label for="last_name" class="col-sm-3 control-label">Nom *</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="last_name">
                    </div>
            </div>

            <div class="form-group">
                <label for="email" class="col-sm-3 control-label">Email *</label>
                    <div class="col-sm-9">
                        <input type="email" class="form-control" id="email">
                    </div>
            </div>

            <div class="form-group">
                <label for="telephone" class="col-sm-3 control-label">Téléphone</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="telephone">
                    </div>
            </div>

            <div class="form-group">
                <label for="comments" class="col-sm-3 control-label">Votre critique *</label>
                    <div class="col-sm-9">
                        <textarea class="form-control" rows="6" id="comments"></textarea>
                    </div>
            </div>

        <div class="col-xs-12 col-sm-9 col-sm-offset-3 text-center">
            <button type="submit" class="btn btn-primary btn-lg btn-block">Envoyer</button>
        </div>
    </div>
</div>
</form>

your inputs have no "name" attribute add a "name" attribute with the same value as the "id" attribute to each input tag as Php uses NAME as the identifier when posted.

To Clearify:

if you try and get an input value from the POST in PHP you have to use the following code:

$var = $_POST['IDENTIFIER'];

Where IDENTIFIER is the value of the "name" attribute of the INPUT or TEXTAREA or any other HTML FORM element you're trying to retrieve.

all your inputs need attribute name="first_name" and etc:

<input type="text" class="form-control" id="first_name" name="first_name">

html_form_send.php must looks like:

<?php 
   if ($_SERVER['REQUEST_METHOD'] == 'POST') {
     $first_name = $_POST['first_name'];
     $last_name = $_POST['last_name'];
     $email = $_POST['email'];
     $telephone = $_POST['telephone'];
     $comments = $_POST['comments'];

     //preparing mail data
     $from = $email;
     $to = "yourmail@exemple.com";
     $subject = "Sending Form From site";
     $message = "First name: $first_name \r\nLast name:$last_name \r\nTelephone: $telephone \r\nComments: $comments";
     $headers = 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
     //sending 
     mail($to, $subject, $message, $headers);

   }
?>

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