发送空白电子邮件的PHP脚本无法获取发布数据

时间:2015-06-23 05:58:05

标签: javascript php html twitter-bootstrap email

index.php顶部的PHP代码。每当我点击提交时,它都会显示已发送的消息,但它会在我的电子邮件地址生成一封空白的电子邮件,而不会发布邮件中的数据。

function GetSysColor(nIndex: Integer): DWORD;
  external 'GetSysColor@User32.dll stdcall';

function ColorToRGB(Color: TColor): Cardinal;
begin
  if Color < 0 then
    Result := GetSysColor(Color and $000000FF) else
    Result := Color;
end;

这是html + php的所有代码

1 个答案:

答案 0 :(得分:0)

好的只是看着它,这里有很多错误。

  • 首先,我不是EOD的忠实粉丝。所以,我把它改为引用。
  • 您的文字需要缩进,认真,否则您无法阅读。

首先让我给你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"
    }
?>

如您所见,我对您的代码进行了一些更改。我确保检查变量是否已设置。这样,您可以触发包含所有变量的邮件。现在每次刷新邮件功能时它都会运行。你不想那样做。如果已发送邮件,我也会对邮件功能进行检查,并为其添加了额外的标题。

您应该尝试做的是对您的输入进行整理。现在它不会在数据库中结束,所以它不是一个大问题,但是,如果你想将它发送到你自己的数据库以供参考呢?添加一个名为mysqli_real_escape_string()的函数很简单(如果你的网站上有数据库函数,你可以使用mysqli。如果你愿意的话,请检查一下。

<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>

我也查看了你的HTML。这里的关键字叫做缩进。 php有一些可疑的位置,我没有得到。这个名字的回声。如果他们是跳棋,那很好,在最终产品中删除它们,如果他们在那里替换名称,你需要添加它们不同。我在评论中如何解决它的问题。 (不确定它是否需要,所以我将解决方案排除在答案之外,您需要的代码已经在这个答案中,您只需要将一些部分放在一起)

修改

我只需要添加(作为交互设计师),需要语音不明智,特别是在转换时(客户端留言的频率)。您希望别人与您联系。将您的电话号码保留在网络上是“个人的”,如果人们要求使用电话号码,它总会让人产生疑问。人们不知道他们的电话会发生什么,所以他们退出了。说明仔细使用信息。

我的提示:不要将手机字段作为必填字段。只是电子邮件,名称和消息。