PHP 邮寄至 Link

PHP Mail to Link

嗨,一切都很快。当我启动时,我的页面抛出了一个 HTML 500 错误,但我根本看不出我的代码有什么问题。我正在尝试在我的网页上创建一个联系表单,当用户单击该表单时,该表单将简单地获取详细信息并通过电子邮件将其发送给我。该页面将不会加载此代码。

            <form method="post">

                <input type="text" name="contact-name" placeholder="Name." required>
                <input type="email" name="contact-email" placeholder="Email." required>
                <input type="text" name="contact-subject" placeholder="Subject." required>
                <br><br>
                <textarea name="contact-content"></textarea>
                <div id="contact-btn-wrap">
                    <input type="submit" name="contact-submit" id="login-btn-signup" value="SEND EMAIL">
                </div>

            </form>
                <br><br><br><br>
                <div class="contact-me">danashton89@gmail.com | 07714709250</div>
            </div>
        </div>
        <div class="contact-img">
            <img src="/uploads/Portfolio/Level_Design/Unreal_Engine/Ice_Cove/icecastle_3.png">
        </div>


        <?php

            $contact-name = "";
            $contact-email = "";
            $contact-subject = "";
            $contact-content = "";

                if (isset($_POST['contact-submit'])) 
                {
                    $contact-name = mysqli_real_escape_string($con, $_POST['contact-name']);
                    $contact-email = mysqli_real_escape_string($con, $_POST['contact-email']);
                    $contact-subject = mysqli_real_escape_string($con, $_POST['contact-subject']);
                    $contact-content = mysqli_real_escape_string($con, $_POST['contact-content']); 

                        $to = "danashton89@gmail.com";
                        $subject = $contact-subject;
                        $txt = $contact-content;
                        $headers = "From: " . $contact-name . "<br>" . $contact-email . "\r\n";
                        $headers.= "MIME-version: 1.0\n";
                        $headers.= "Content-type: text/html; charset= iso-8859-1\n";

                    mail($to,$subject,$txt,$headers);
                }

        ?>

我认为您不能在变量名称中使用破折号($contact-name ...)

首先,您不能在 php 中使用 '-'

声明变量

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'

其次,你的connection var定义了吗?

最后,能否提供错误字符串?