A
A
Artem Shulyak2022-02-09 12:26:51
PHP
Artem Shulyak, 2022-02-09 12:26:51

Do hieroglyphs come to the mail from the feedback form?

<?php
                require __DIR__ . "/functions.php";

                if (isset($_POST["submit"])) {
                    $name = $_POST["name"];
                    $email = $_POST["email"];
                    $subject = $_POST["subject"];
                    $message = $_POST["message"];

          

                    // $errors = validation($_POST);


                    if (empty($errors)) {
                        send($name, $email, $subject, $message);
                    } 
                }
                ?>


<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require __DIR__ . "/libs/PHPMailer/Exception.php";
require __DIR__ . "/libs/PHPMailer/PHPMailer.php";
require __DIR__ . "/libs/PHPMailer/SMTP.php";

function validation($data)
{
    $errors = [];


    if (empty($data["name"])) {
        $errors["name"] = "erros";
    }
    if (empty($data["email"])) {
        $errors["email"] = "erros";
    }
    if (empty($data["subject"])) {
        $errors["subject"] = "erros";
    }
    if (empty($data["message"])) {
        $errors["message"] = "erros";
    }

    return $errors;
}

function send($name, $email, $subject, $message)
{
    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = "smtp.mail.ru";
    $mail->SMTPAuth = true;
    $mail->Username = "[email protected]";
    $mail->Password = "ЗАМАЗАНО";
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port = 465;

    $mail->setFrom("[email protected]", 'Small Apps');
    $mail->addAddress("[email protected]", 'Mikhail Protasevich');

    $mail->isHTML(true);
    $mail->Subject = "Small Apps: $subject";
    $mail->Body = "Name: $name<br>E-mail: $email<br>Message: $message";

    try {
        $mail->send();
        ?>
        <div class="success" >
            Message sent
        </div>
        <?php
    }  catch (Exception $exception) {
        ?>
        <div>
            <?= $exception->getMessage() ?>
        </div>
        <?php
    }
}

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2022-02-09
@Rsa97

$mail->CharSet = "utf-8";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question