Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发送空白电子邮件的php脚本无法获取帖子数据_Javascript_Php_Html_Twitter Bootstrap_Email - Fatal编程技术网

Javascript 发送空白电子邮件的php脚本无法获取帖子数据

Javascript 发送空白电子邮件的php脚本无法获取帖子数据,javascript,php,html,twitter-bootstrap,email,Javascript,Php,Html,Twitter Bootstrap,Email,index.PHP顶部的PHP代码。每当我点击“提交”按钮时,它就会显示已发送的消息,但它会生成一封发送到我电子邮件地址的空白电子邮件,而不会从帖子中捕获数据 <?php $emailSubject = 'Customer Has a Question!'; $webMaster = 'admin@princosoft.com'; $name = $_POST['iname']; $email = $_POST['iemail']; $phon

index.PHP顶部的PHP代码。每当我点击“提交”按钮时,它就会显示已发送的消息,但它会生成一封发送到我电子邮件地址的空白电子邮件,而不会从帖子中捕获数据

<?php   
    $emailSubject = 'Customer Has a Question!';
    $webMaster = 'admin@princosoft.com';
    $name = $_POST['iname'];
    $email = $_POST['iemail'];
    $phone=$_POST['iphone'];
    $question = $_POST['imessage'];
    echo $name;
    $body = <<<EOD
    <br><hr><br>
    Name: $name <br>
    Email: $email <br>
    Questions: $question <br>
    EOD;
    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($webMaster, $emailSubject, $body, $headers);
    $theResults = <<<EOD
    EOD;
    echo "$theResults";
?>
<div class="col-lg-12">
    <form name="sentMessage" action="/index.php" method="post" id="contactForm" novalidate >
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <input type="text" name="iname" class="form-control" 
                        placeholder="Your Name  *" 
                        id="name"  
                        required data-validation-required-message="Please enter your  name.">
                    <?php  $name = $_POST['iname']; ?>
                    <p class="help-block text-danger"></p>
                </div>
                <div class="form-group">
                    <input type="email" name="iemail" class="form-control" 
                        placeholder="Your Email *" id="email"  
                        required data-validation-required-message="Please enter your email address.">
                        <?php  $name = $_POST['iemail']; ?>
                    <p class="help-block text-danger"></p>
                </div>
                <div class="form-group">
                    <input type="tel" name="iphone" 
                        class="form-control" 
                        placeholder="Your Phone *" id="phone"  
                        required data-validation-required-message="Please enter your phone number.">
                        <?php  $name = $_POST['iphone']; ?>
                    <p class="help-block text-danger"></p>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <textarea class="form-control"name="imessage" placeholder="Your Message *" 
                        id="message"  
                        required data-validation-required-message="Please enter a
                        message.">/textarea>
                    <?php  $name = $_POST['imessage']; ?>
                    <p class="help-block text-danger"></p>
                </div>
            </div>
            <div class="clearfix"></div>
                <div class="col-lg-12 text-center">
                    <div id="success"></div>
                    <button type="submit" name="isubmit" class="btn btn-xl">Send Message</button>
                </div>
            </div>
        </form>

/text区域>

发送消息

这是html+php的全部代码

好的,看看它,这里有很多错误

  • 首先,我不是一个大的球迷对排爆。所以,我把它改为引文
  • 你的文字需要缩进,说真的,否则你就看不懂了
让我先给你php,然后是html

<?php 
    print_r($_POST);  

    if (isset($_POST['isubmit'])){ // checking if the submit button variable is there from clicking on the button
        // mail variables

        $emailSubject = 'Customer Has a Question!';
        $webMaster = 'admin@princosoft.com';
        $name = $_POST['iname'];
        $email = $_POST['iemail'];
        $phone=$_POST['iphone'];  // please note this variable is not used anymore in the code. You either forgot it in your email, or you dont want anything with this
        $question = $_POST['imessage'];

        echo $name;

        //set up mail body
        $body = "<br><hr><br>";
        $body .= "Name:". $name . "<br>";
        $body .= "Email:". $email ."<br>";
        $body .= "Questions:". $question ."<br>";

        $headers = "From: $email\r\n";
        $headers .= "Content-type: text/html\r\n";
        $headers .= "MIME-Version: 1.0" . "\r\n";

        if (mail($webMaster, $emailSubject, $body, $headers)){
            echo "your mail has been send succesfully";
        }
    } else {
        // this is a test message. Just erase the whole else statement when this all works (for test purposes if the code is read)
        echo "variables aren't set yet"
    }
?>
我还看了你的html。这里的键称为缩进。php的位置有一些问题,我没有得到。名字的回声。如果它们是checker,那很好,在最终产品中删除它们,如果它们是用来替换名称的,则需要添加不同的名称。我评论了它是如何解决的。(不确定是否需要,所以我在答案中没有给出解决方案,您需要的代码已经在这个答案中,您只需将一些片段组合在一起)

编辑

我只需要补充一点(作为交互设计师),需要一个电话号码是不明智的,特别是在转换时(客户会多长时间留言)。你希望人们联系你。把你的电话号码留在网上是一件“私人”的事情,如果有人要你的电话号码,这会让人产生怀疑。人们不知道他们的电话号码会发生什么,所以他们放弃了。说明信息使用谨慎


我的建议:不要将电话字段设为必填字段。只有电子邮件、姓名和信息

您是如何发布数据的?请稍候,让我添加html代码您在此处出现语法错误:
“请输入消息。”>/textarea>
未正确关闭
textarea
。您需要在此处设置一些格式(读取缩进),lol.
EOD
不应该缩进…我完全按照你说的那样尝试了,但它仍然没有生成和发送电子邮件,消息端变量仍然没有设置,甚至在我单击submit按钮更新它之后,我在操作中添加了php self命令,我意识到我忘了把它放在那里。检查它现在是否工作。由于您将其提交到同一页面,因此action属性可以省略或为空,但显然没有。现在要做的是检查post变量。我在php代码中添加了一行,显示了post方法推送的所有变量。看看有没有结果。哦,我看到我在
$\u POST
变量上犯了一个拼写错误。那可能是你的问题。再检查一遍
<form name="sentMessage" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="contactForm" novalidate >
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <input type="text" name="iname" class="form-control" placeholder="Your Name  *" id="name" required data-validation-required-message="Please enter your  name.">
                    <?php  $name = $_POST['iname']; // i leave this here, but i would remove this. It has no purpose, if you want to replace the name in your field, check if variable is set, and put it in the name field of your item ?>
                <p class="help-block text-danger"></p>
            </div>
            <div class="form-group">
                <input type="email" name="iemail" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                    <?php  $name = $_POST['iemail']; // i leave this here, but i would remove this. It has no purpose, if you want to replace the name in your field, check if variable is set, and put it in the name field of your item ?>
                <p class="help-block text-danger"></p>
            </div>
            <div class="form-group">
                <input type="tel" name="iphone" class="form-control" placeholder="Your Phone *" id="phone"  required data-validation-required-message="Please enter your phone number.">
                    <?php  $name = $_POST['iphone'];// i leave this here, but i would remove this. It has no purpose, if you want to replace the name in your field, check if variable is set, and put it in the name field of your item  ?>
                <p class="help-block text-danger"></p>
            </div>
        </div>

        <div class="col-md-6">
            <div class="form-group">
                <textarea class="form-control"name="imessage" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea> <!-- issue here with wrong closing of text area in html -->
                    <?php  $name = $_POST['imessage']; // i leave this here, but i would remove this. It has no purpose, if you want to replace the name in your field, check if variable is set, and put it in the name field of your item ?>
                <p class="help-block text-danger"></p>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="col-lg-12 text-center">
            <div id="success"></div>
            <button type="submit" name="isubmit" class="btn btn-xl">Send Message</button>
        </div>
    </div>
</form>