Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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
PHP电子邮件不';不要发送电子邮件_Php_Email - Fatal编程技术网

PHP电子邮件不';不要发送电子邮件

PHP电子邮件不';不要发送电子邮件,php,email,Php,Email,我有一个网站,希望人们能够通过表格给我发送电子邮件。 我遵循了本教程,但它没有发送电子邮件 <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message'];

我有一个网站,希望人们能够通过表格给我发送电子邮件。 我遵循了本教程,但它没有发送电子邮件

                        <?php
                            $name = $_POST['name'];
                            $email = $_POST['email'];
                            $message = $_POST['message'];
                            $from = 'From: FPSUsename.xyz';
                            $to = 'FPSUsername@outlook.com';
                            $subject = $_POST['subject'];

                            $body = "From: $name\n E-Mail: $email\n Message:\n $message";

                            if ($_POST['submit']) {
                                if (mail ($to, $subject, $body, $from)) { 
                                    echo '<p>Your message has been sent!</p>';
                                } else { 
                                    echo '<p>Something went wrong, go back and try again!</p>'; 
                                }
                            }
                        ?>

                        <form method="post" action="index.php">
                            <div class="field">
                                <label for="name">Name</label>
                                <input type="text" name="name" placeholder="Your Name">
                            </div>
                            <div class="field">
                                <label for="email">Email</label>
                                <input type="email" name="email" placeholder="Your Email">
                            </div>
                            <div class="field">
                                <label for="subject">Subject</label>
                                <input type="text" name="subject" placeholder="Subject"/>
                            </div>
                            <div class="field">
                                <label for="message">Message</label>
                                <textarea name="message" id="message" rows="4" placeholder="Message"></textarea>
                            </div>
                            <ul class="actions">
                                <li><input type="submit" id="submit" name="submit" value="Submit" /></li>
                            </ul>
                        </form>

名称
电子邮件
主题
消息
这是代码,但它总是显示“您的消息已发送!”即使我没有填写任何内容。
有人能帮我吗?

您还没有对函数进行任何验证,因此这就是原因:

您的信息已发送!“即使我什么都没填。 谁能帮帮我吗

如果你没有收到数据,也要检查你的垃圾邮件


几个月前,我遇到了这个问题,并了解到主机不会一直自动尝试向客户端重新发送消息,因此这也可能是错误所在。

尝试添加验证。您不需要添加jQuery验证,您可以在输入字段中添加一个非常简单的带有required的验证,然后提交表单。然后进行检查你的垃圾邮件文件夹


如果还有什么需要我帮忙的,请告诉我。

好吧,您根本没有对提交的数据进行任何验证,以确保任何字段都包含任何内容。您期望得到什么?另外,您似乎有两个不同的问题。问题是它没有在应该发送邮件的时候发送邮件?还是它说“您的邮件已发送”“当您将字段留空时?当您将字段留空时,它会显示“您的邮件已发送”,但我使用required/在每个输入字段上对其进行了修复。它将它们发送到我的垃圾邮件文件夹,很好,但我如何进行验证?您只需将required添加到您的输入字段示例中,将其添加到您的all input元素中即可。”。它会起作用,但请记住这是一个非常基本的验证。如果它对你起作用,请检查这个答案是否正确。它有利于堆栈溢出跟踪。