简体   繁体   English

Contact.php发送电子邮件,但内部没有文本消息

[英]Contact.php send emails but without the text message inside

I implemented the following contact form on my website (from a template), and I can send and receive an email message successfully, but the message part (the users text) is NOT received in my Inbox. 我在网站上(从模板)实施了以下联系表,并且可以成功发送和接收电子邮件,但是收件箱中未收到消息部分(用户文本)。 I receive the Name and From Email, but not the content of the message. 我收到名称和发件人电子邮件,但没有收到邮件内容。

screenshot from the website form 网站表单的屏幕截图

Can someone help finding and fixing the issue? 有人可以帮助找到并解决问题吗? It is the php, the jQuery or the html wrong? 是php,jQuery还是html错误?

HTML: HTML:

<form action="contact.php" class="contact_form" id="form" method="post">
                <div class="col-lg-6 col-md-6 col-lg-offset-3 col-md-offset-3">
                    <span class="input input_name">
                        <input class="input__field" type="text" name="name" id="name" required/>
                        <label class="input__label" for="name">
                        <span class="input__label_content">Name</span>
                        </label>
                    </span>
                    <span class="input input_website">
                        <input class="input__field" type="url" name="website" id="website" />
                        <label class="input__label" for="website">
                        <span class="input__label_content">Website</span>
                        </label>
                    </span>
                    <span class="input input_mail">
                        <input class="input__field" type="email" name="email" id="email" required/>
                        <label class="input__label" for="email">
                        <span class="input__label_content">email</span>
                        </label>
                    </span>
                </div>
                <div class="col-lg-8 col-md-8 col-lg-offset-2 col-md-offset-2">
                    <span class="textarea">
                        <textarea class="textarea_field" name="textarea" id="textarea" rows="4" placeholder="type your text here . . . ."></textarea>
                    </span>
                    <span class="submit">
                        <button type="submit" class="rms-btn submit_btn" id="submit">submit request <span><i class="fa fa-pencil"></i></span></button>
                    </span>
                </div>
            </form>

contact.php: contact.php:

<?php
/*
* Ajax form submit
*/

# request sent using HTTP_X_REQUESTED_WITH
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ){
        if (isset($_POST['name']) AND isset($_POST['email'])  AND isset($_POST['textarea'])) {
                $to = 'info@antarescodestudio.com'; /* Add your contact email address here */

                $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
                $subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
                $message = filter_var($_POST['textarea'], FILTER_SANITIZE_STRING);
                $sent = email($to, $email, $name, $message);
                if ($sent) {
                        echo 'Message sent!';
                } else {
                        echo 'Message couldn\'t sent!';
                }
        }
        else {
                echo 'All Fields are required';
        }
        return;
}

/**
 * email function
 *
 * @return bool | void
 **/
function email($to, $from_mail, $from_name, $subject, $message){
        $header = array();
        //$header[] = "MIME-Version: 1.0";
        $header[] = "From: {$from_name} < {$from_mail}>";
        $header[] = "Message: {$message}";
        /* Set message content type HTML*/
        /*$header[] = "Content-type:text/html; charset=iso-8859-1";*/
        /*$header[] = "Content-Transfer-Encoding: 7bit";*/
        if( mail($to, $message, implode("\r\n", $header)) ) return true;
}

?>

contact.js contact.js

jQuery(document).ready(function() {
    var form = jQuery('#form'); // contact form
    var submit = jQuery('#submit'); // submit button
    var alert = jQuery('.alert'); // alert div for show alert message

    // form submit event
    form.on('submit', function(e) {
        e.preventDefault(); // prevent default form submit
        // sending ajax request through jQuery
        jQuery.ajax({
            url: 'contact.php', // form action url
            type: 'POST', // form submit method get/post
            dataType: 'html', // request type html/json/xml
            data: form.serialize(), // serialize form data 
            beforeSend: function() {
                alert.fadeOut();
                submit.html('Sending....'); // change submit button text
            },
            success: function(data) {
                alert.html(data).fadeIn(); // fade in response data
                form.trigger('reset'); // reset form
                submit.html('Email Sent <span> <i class="fa fa-check"></i> </span>'); // reset submit button text
            },
            error: function(e) {
                console.log(e)
            }
        });
    });
});

Thanks! 谢谢!

Replace 更换

$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);

with

$message = filter_var($_POST['textarea'], FILTER_SANITIZE_STRING);

Edit: Also this line is questionable: 编辑:另外此行是可疑的:

$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);

There are no fields with a name subject . 没有名称subject字段。

Your text area has the name 'textarea', while in your php file you are processing $_POST['message'] . 您的文本区域的名称为'textarea',而在php文件中,您正在处理$_POST['message'] Change the name of the textarea to 'message' or $_POST['message'] to $_POST['textarea'] 将textarea的名称更改为'message'或将$_POST['message']更改$_POST['textarea']

我看起来textarea是表单上的名称textarea ,但是您引用的是一个称为message的POST变量。

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

相关问题 contact.php上的验证错误:如何显示多个验证错误消息? - Validation Errors on contact.php: How to show more than 1 validation error message? 找不到带有contact.php文件的Javascript联系人表格或内部服务器错误 - Javascript contact form with contact.php file not found or internal server error php .session_start在commit.php上显示contact.php上的错误 - php .session_start show errors on contact.php from submit.php 如果Div里面有某些文本,则将消息发送到php,然后发送到.txt? JQuery的/ JS / PHP - If Div has certain text inside of it send message to php and then to .txt? JQuery/js/PHP linkedin-使用php或javascript导入联系人并发送消息 - linkedin - import contact and send message using php or javascript 重制此“联系表”以发送电子邮件(Ajax) - Remake of this “contact form” to send out emails (Ajax) AJAX / JQuery和PHP发送提示而无需重新加载联系表 - AJAX/JQuery and PHP to send prompt without reload for a contact form WhatsApp API将消息发送给联系人 - WhatsApp api to send message to contact 如何使联系我们提交按钮将电子邮件发送到我的电子邮件? - How to make the contact us submit button send emails to my email? 通过不带后端的mailjet发送电子邮件 - Send emails via mailjet without backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM