PHPMailer с HTML контактной формой - PullRequest
1 голос
/ 15 января 2020

Извините за мой плохой Engli sh :( У меня здесь большая проблема, у меня есть html домашняя страница с контактной формой там. Я хотел бы, чтобы эта форма отправлялась с PHPMailer, когда я отправляю сообщение, которое я получаю это, но без текста: / Я вижу только пример текста, например "Вот тема". Может кто-нибудь помочь мне, пожалуйста?

вот phpmailer. php код:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 0;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.test.de';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'MY EMAIL';                 // SMTP username
    $mail->Password = 'MY PASSWORT!';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                           // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('MY EMAIL');
    $mail->addAddress('MY EMAIL');     // Add a recipient



    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>

МОЙ ЭЛЕКТРОННЫЙ ПОЧТЕН здесь просто для безопасности

А вот код из html контактной формы:

<!-- Contact Form -->
<div class="row">
    <div class="col-md-8 col-md-offset-2">

        <form action="phpmailer_new.php" method="POST">
            <div class="form-group">
                <input type="text" name="mail" class="form-control" placeholder="Email Address">
            </div>
            <div class="form-group">
                <input type="text" name="subject" class="form-control" placeholder="Subject">
            </div>
            <div class="form-group">
                <textarea class="form-control" name="text" rows="3" placeholder="Your Message"></textarea>
                <button class="btn btn-default" type="submit">Send Message</button>
            </div>
        </form>
    </div>
</div>
<!-- End Contact Form -->

Приветствия Ив

1 Ответ

1 голос
/ 15 января 2020

Вам необходимо добавить переменные $ _POST в ваш скрипт PHPmailer:

  <?php
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    require 'src/Exception.php';
    require 'src/PHPMailer.php';
    require 'src/SMTP.php';

    $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
    try {
        //Server settings
        $mail->SMTPDebug = 0;                                 // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.test.de';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'MY EMAIL';                 // SMTP username
        $mail->Password = 'MY PASSWORT!';                           // SMTP password
        $mail->SMTPSecure = 'ssl';                           // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 465;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom('MY EMAIL');
        $mail->addAddress($_POST['mail']);     // Add a recipient



        //Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $_POST['subject'];
        $mail->Body    = $_POST['text'];

        $mail->send();
        //echo 'Message has been sent';
        header('Location: http://www.example.com/contact.php');
        exit();
    } catch (Exception $e) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }
    ?>
...