简体   繁体   English

Contactform.php没有发送所有输入

[英]Contactform.php not sending all inputs

I have a contact form that is working fine, it sends the email except that it doesn't post the email address of the person that sends it. 我有一个联系表格,可以正常工作,它可以发送电子邮件,但它不会张贴发送电子邮件的人的电子邮件地址 I have no idea why, I tried changing the $from variable and nothing changes. 我不知道为什么,我尝试更改$ from变量,但没有任何变化。 Is there something obvious I am missing? 有什么明显的我想念的东西吗?

It is the input with the id c_email which is put into the $from variable that I do not receive in the emails sent by this form. 这是ID为c_email的输入,该输入被放入$ from变量中,在此表单发送的电子邮件中我没有收到。

My contactform.php: 我的contactform.php:

<?php

// Contact
$to = 'myemail@gmail.com';
    $subject = 'Portfolio ContactForm';

if(isset($_POST['c_name']) && isset($_POST['c_email']) && isset($_POST['c_message'])){
$name    = $_POST['c_name'];
    $from   = $_POST['c_email'];
    $message = $_POST['c_message'];

    if (mail($to, $subject, $from, $name, $message)) { 
        $result = array(
            'message' => 'Sent, thanks!',
            'sendstatus' => 1
            );
        echo json_encode($result);
    } else { 
        $result = array(
            'message' => 'Ooops, problem..',
            'sendstatus' => 1
            );
        echo json_encode($result);
    } 
}?>

On my html page: 在我的html页面上:

<form id="contact-form" role="form">

        <div class="form-group">
            <label class="sr-only" for="c_name">Name</label>
            <input type="text" id="c_name" class="form-control" name="c_name" placeholder="Nom">
        </div>

        <div class="form-group">
            <label class="sr-only" for="c_email">Email address</label>
            <input type="email" id="c_email" class="form-control" name="c_email" placeholder="E-mail">
        </div>

        <div class="form-group">
            <textarea class="form-control" id="c_message" name="c_message" rows="7" placeholder="Votre message"></textarea>
        </div>

        <button type="submit" class="btn btn-custom-1">
                <i class="fa fa-bullhorn icon-before"></i> Envoyer
        </button>

</form>

Your values is not posting because in your form you not mention method="POST" .Just try like this.it should work 您的值未发布,因为在表单中您未提及method =“ POST” 。只需尝试这样。它应该可以工作

<form id="contact-form" role="form" action="" method="POST">

    <div class="form-group">
        <label class="sr-only" for="c_name">Name</label>
        <input type="text" id="c_name" class="form-control" name="c_name" placeholder="Nom">
    </div>

    <div class="form-group">
        <label class="sr-only" for="c_email">Email address</label>
        <input type="email" id="c_email" class="form-control" name="c_email" placeholder="E-mail">
    </div>

    <div class="form-group">
        <textarea class="form-control" id="c_message" name="c_message" rows="7" placeholder="Votre message"></textarea>
    </div>

    <button type="submit" class="btn btn-custom-1">
            <i class="fa fa-bullhorn icon-before"></i> Envoyer
    </button>

</form>
<script>
$('button').click(function() {
var c_name = $("#c_name").val();
var c_email = $("#c_email").val();
var c_message = $("#c_message").val();
$.ajax({//create an ajax request to load_page.php
type: "POST",
url: "assets/php/contactForm.php",
data:{"c_name":c_name,"c_email":c_email,"c_message":c_message},
success: function(data) {
    if (data) {

       alert(data);
    }
    else {
        alert('Successfully not posted.');
    }
}
});
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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