PHP联系表单不发送邮件,导致空白页

时间:2017-09-05 15:42:08

标签: php email

尝试通过我网站的联系表单发送邮件会导致出现空白页面(没有确认消息),也没有发送电子邮件。

表单的HTML是:

<form method="post" action="index.php">
    <div class="field half first">
        <label for="name">Name</label>
        <input type="text" name="name" id="name" />
    </div>
    <div class="field half">
        <label for="email">Email</label>
        <input type="text" name="email" id="email" />
    </div>
    <div class="field">
        <label for="message">Message</label>
        <textarea name="message" id="message" rows="4"></textarea>
    </div>
    <ul class="actions">
        <li><input type="submit" value="Send Message" class="special" /></li>
        <li><input type="reset" value="Reset" /></li>
    </ul>
</form> 

index.php文件是:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: SiteContactForm'; 
    $to = 'xxxx@xxxmail.net'; 
    $subject = 'Hello';

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

if (isset($_POST['submit'])) {
    if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Your email has been sent.</p>';
    } else { 
        echo '<p>Something broke.</p>'; 
    }
}
?>

这里是否有任何错误导致事情破裂? 'to'电子邮件是我的实际电子邮件,只是在这里编辑。

1 个答案:

答案 0 :(得分:0)

尝试这种方式,您需要命名提交

if (isset($_POST['submit']))

否则var hamburger = document.querySelector(".hamburger"); var header = document.querySelector(".header"); // On click hamburger.addEventListener("click", function() { // Toggle class "is-active" hamburger.classList.toggle("is-active"); header.classList.toggle("header--is-active"); // Do something else, like open/close menu });将无效,因为它正在寻找通过

设置/发送的“提交”