PHP - 使用xampp本地主机无法正常发送邮件

时间:2015-09-17 06:44:07

标签: php mysql phpmyadmin xampp localhost

我正在尝试建立一个基本的预订系统。 当通过.html文档进行预订时,它应该将邮件发送到我的电子邮件地址。但事实并非如此。

我通过localhost搜索了Xampp的邮件,发现了一些更改php.ini和sendmail.ini文件的帖子,将smtp设置更改为gmail。

但我无法让它发挥作用。 我是做错了什么还是忽视/遗忘了什么? 有没有其他方法来测试我的代码,如果它的工作,然后尝试使用Xampp?

如果需要,我可以发布我的php.ini和sendmail.ini文件。

PHP代码

<?php

    $message = "";

    //email adres
    $email = "tom.deboeck23@gmail.com";

    $required = array('dag', 'maand', 'jaar', 'uur', 'minuten', 'naam','email', 'telefoon', 'aantal', 'bericht', 'type');

    if (isset($_POST['reserveren']))
    {
        $data = $_POST['reservatie'];

        $headers = "";

        $message .= "Dag Lode en Eva, via de website kregen jullie een nieuwe reservatie, gelieve de persoon zo snel mogelijk een bevestigingsmail te sturen!";
        $message .= "\n\n";
        $message .= $data['bericht'];
        $message .= "\n\n";

        $message .= "Telefoon: " . $data['telefoon'];
        $message .= "\n\n";
        $message .= "Lunch/Diner: " . $data['type'];
        $message .= "\n\n"; 
        $message .= "Aantal personen: " . $data['aantal'];
        $message .= "\n\n";
        $message .= "Email: " . $data['email'];
        $message .= "\n\n";

        $message .= "Datum: " . $data['dag'];
        $message .= "\n\n";
        $message .= "Maand: " . $data['maand'];
        $message .= " " . $data['jaar'];
        $message .= "\n\n";
        $message .= " Tijdstip: " . $data['uur'] . " " . $data['minuten'];

        $subject = 'Nieuwe reservatie via de website';
        $headers = 'From: '. $data['email']. "\r\n" .'Reply-To: '. $data['email']. "\r\n" .'X-Mailer: PHP/' . phpversion();

        if (mail($email, $subject, $message, $headers))
        {
           echo "mail verstuurd!";
        }           
    }    
?>

HTML代码

<!DOCTYPE html>
<html>

    <head>
        <meta charset ="UTF-8">
        <title>Baronie - Reservatie</title>

    </head>
    <body>

        <form action='reservatie.php' method="post">

            <h4>Gewenste datum</h4>

                <select id="dag" name="reservatie[dag]">
                    <option value="01">01</option>
                    <option value="02">02</option>
                    <option value="03">03</option>
                    <option value="04">04</option>
                    <option value="05">05</option>
                    <option value="06">06</option>
                    <option value="07">07</option>
                    <option value="08">08</option>
                    <option value="09">09</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                    <option value="13">13</option>
                    <option value="14">14</option>
                    <option value="15">15</option>
                    <option value="16">16</option>
                    <option value="17">17</option>
                    <option value="18">18</option>
                    <option value="19">19</option>
                    <option value="20">20</option>
                    <option value="21">21</option>
                    <option value="22">22</option>
                    <option value="23">23</option>
                    <option value="24">24</option>
                    <option value="25">25</option>
                    <option value="26">26</option>
                    <option value="27">27</option>
                    <option value="28">28</option>
                    <option value="29">29</option>
                    <option value="30">30</option>
                </select>

                <select id="maand" name="reservatie[maand]">
                    <option value="Januari">Januari</option>
                    <option value="Februari">Februari</option>
                    <option value="Maart">Maart</option>
                    <option value="April">April</option>
                    <option value="Mei">Mei</option>
                    <option value="Juni">Juni</option>
                    <option value="Juli">Juli</option>
                    <option value="Augustus">Augustus</option>
                    <option value="September">September</option>
                    <option value="Oktober">Oktober</option>
                    <option value="November">November</option>
                    <option value="December">December</option>
                </select>   

                <select id="jaar" name="reservatie[jaar]">
                    <option value="2015">2015</option>
                    <option value="2016">2016</option>
                </select>   

            <h4>Gewenste tijdstip</h4>

                <select id="uur" name="reservatie[uur]">
                    <option value="12">12u</option>
                    <option value="13">13u</option>
                    <option value="14">14u</option>             
                    <option value="18">18u</option>
                    <option value="19">19u</option>
                    <option value="20">20u</option>
                    <option value="21">21u</option>                 
                </select>

                <select id="minuten" name="reservatie[minuten]">
                    <option value="00">00 min</option>
                    <option value="05">05 min</option>
                    <option value="10">10 min </option>
                    <option value="15">15 min</option>
                    <option value="20">20 min </option>
                    <option value="25">25 min </option>
                    <option value="30">30 min </option>
                    <option value="35">35 min </option>
                    <option value="40">40 min </option>
                    <option value="45">45 min</option>
                    <option value="50">50 min </option>
                    <option value="55">55 min</option>
                </select>

            <h4>Reservatie</h4>

                <select id="type" name="reservatie[type]">
                    <option value="Diner">Diner</option>
                    <option value="Middaglunch">Lunch</option>
                </select><br><br>

                <input type="text" id="aantal" placeholder="Aantal personen" name="reservatie[aantal]"><br><br>

                <input type="text" id="naam" placeholder="Naam" name="reservatie[naam]"><br><br>

                <input type="text" id="email" placeholder="Email" name="reservatie[email]"><br><br>

                <input type="tel" id="telefoon" placeholder="Telefoon" name="reservatie[telefoon]"><br><br>

                <textarea id="bericht" placeholder="Bericht" name="reservatie[bericht]"></textarea><br><br><br>

                <input type="submit" name="reserveren" value="Reserveren">
        </form>

    </body> 
</html>

0 个答案:

没有答案