如何测试PHP邮件系统?

时间:2018-09-12 21:29:41

标签: php forms email xampp phpmailer

我已经有了用于测试此PHP联系人表单的基本代码,但是它似乎不起作用。我正在通过XAMPP运行它,也正在使用PHPMailer。由于我还没有smtp,因此我在mailtrap.io上创建了一个免费的。当我单击提交按钮时,它仅打开PHP脚本。您能否检查一下,可能出什么问题了?预先谢谢你。

HTML:

<div class="kontakt1" id="kontakt">
                <form action="buchung.php" method="post">
                    <div class="card border-primary rounded-0">
                        <div class="card-header p-0">
                            <div class="bg-info text-white text-center py-2">
                                <h3><i class="fa fa-envelope"></i>Írjon üzenetet!</h3>
                                <p class="m-0">Kérjen árajánlatot!</p>
                            </div>
                        </div>
                        <div class="card-body p-3">

                            <!--Body-->
                            <div class="form-group">
                                <div class="input-group mb-2">
                                    <div class="input-group-prepend">
                                        <div class="input-group-text"><i class="fa fa-user text-info"></i></div>
                                    </div>
                                    <input type="text" class="form-control" id="nombre" name="name" placeholder="Név" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="input-group mb-2">
                                    <div class="input-group-prepend">
                                        <div class="input-group-text"><i class="fa fa-envelope text-info"></i></div>
                                    </div>
                                    <input type="email" class="form-control" id="nombre" name="Email" placeholder="E-mail cím" required>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="input-group mb-2">
                                    <div class="input-group-prepend">
                                        <div class="input-group-text"><i class="fa fa-comment text-info"></i></div>
                                    </div>
                                    <textarea class="form-control" placeholder="Üzenet" required></textarea>
                                </div>
                            </div>

                            <label class="container">Elfogadom az <a href="megatrend-gdpr.pdf">Adatvédelmi Tájékoztató</a>ban foglatakat.
                              <input type="checkbox" checked="checked">
                              <span class="checkmark"></span>
                            </label>



                            <div class="text-center">
                                <input type="submit" value="Küldés" class="btn btn-info btn-block rounded-0 py-2">
                            </div>
                        </div>

                    </div>
                </form>
            </div>

(我使用过引导程序。)

PHP:

<!DOCTYPE html>
<html lang="en" class="no-js">
<!-- BEGIN HEAD -->

<head>
    <meta charset="utf-8"/>
    <title>test</title>


</head>
<!-- END HEAD -->




<!-- BODY -->

<body>



    <?php

    require 'phpmailer/PHPMailerAutoload.php';

    $name= $_POST['name'];
    $kundenmail= $_POST['mail'];
    $message= $_POST['message'];
    $datum = date("Y-m-d H:i");

    if(empty($name)){
        echo("<center><font size='+2' color='white'><div style='margin-top:20%;'>Hiba keletkezett a rendszerben.</div></font></center>");
        exit();
    }

    $mail = new PHPMailer;
    $name= $_POST['name'];
    $kundenmail= $_POST['mail'];
    $nachricht= $_POST['nachricht'];
    $datum = date("Y-m-d H:i");
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.mailtrap.io';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'e2418d1b2b7411';                 // SMTP username
    $mail->Password = '9e998b00d78710';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 25;                                    // TCP port to connect to
    $mail->CharSet = "UTF-8";
    $mail->setFrom('tothmatee97@gmail.com', 'Máté');
    $mail->addReplyTo('tothmatee97@gmail.com', 'Máté');
    $mail->addAddress("tothmatee97@gmail.com");
    $mail->isHTML(true);                                  // Set email format to HTML                                // Set email format to HTML
    $mail->Subject = 'Köszönjük Üzenetét!';
    $mail->Body    = 'Név:'.$name
                                    .'<br>E-mail cím:'.$kundenmail
                                    .'<br>Üzenet:'.$message;

                    if($mail->send()){
                    echo "funktioniert";

                }else{
                    echo "nicht";
                }


    ?>




    <h6>Danke.</h6>









</body>
<!-- END BODY -->

</html>

0 个答案:

没有答案