PHP 带有西班牙口音的电子邮件显示不正确

PHP Email with Spanish accents incorrectly showing

我的网站是salonesvip.cl

网站本身完美地显示了西班牙口音,没有问题。 在联系表本身中,它显示了西班牙口音。 一旦他们点击发送就生成并到达我的电子邮件...这就是问题所在。

我唯一的猜测是 PHP,因为网站显示没有问题。

我花了几个小时试图找到解决方案,但我真的找不到解决办法。

我附上 php,希望有人知道问题出在哪里...如果您需要更多信息,请告诉我。

谢谢

mailer.php

<?php
// Only process POST reqeusts.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Get the form fields and remove whitespace.
    $name = strip_tags(trim($_POST["name"]));
            $name = str_replace(array("\r","\n"),array(" "," "),$name);
    $salon = $_POST["salon"];
    $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
    $celu = trim($_POST["celu"]);
    $creditCard = trim($_POST["creditCard"]);
    $subjectwa = $_POST["subject"];
    $message = trim($_POST["message"]);

    // Check that data was sent to the mailer.
    if ( empty($name) OR empty($message) OR empty($celu) OR empty($creditCard) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
        // Set a 400 (bad request) response code and exit.
        http_response_code(400);
        echo "Oops! No se puede enviar el formulario, verifica los campos.";
        exit;
    }

    // Set the recipient email address.
    // FIXME: Update this to your desired email address.
    $recipient = "XXX@salonesvip.cl";

    // Set the email subject.
    $subject = "Contacto desde el sitio web.  Su nombre es: $name";

    // Build the email content.
    $email_content = "Name: $name\n\n";
    $email_content .= "Salon: $salon\n\n";
    $email_content .= "Email: $email\n\n";
    $email_content .= "Celular: $celu\n\n";
    $email_content .= "Credit Card: $creditCard\n\n";
    $email_content .= "Subject: $subjectwa\n\n";
    $email_content .= "Message:\n$message\n";

    // Build the email headers.
    $email_headers = "From: $name <$email>";

    // Send the email.
    if (mail($recipient, $subject, $email_content, $email_headers)) {
        // Set a 200 (okay) response code.
        http_response_code(200);
        echo "Gracias! Su mensaje ha sido enviado.";
    } else {
        // Set a 500 (internal server error) response code.
        http_response_code(500);
        echo "Oops! No se puede enviar el formulario, verifica los campos.";
    }

} else {
    // Not a POST request, set a 403 (forbidden) response code.
    http_response_code(403);
    echo "Oops! No se puede enviar el formulario, verifica los campos.";
}

?>

尝试在电子邮件中设置编码 header (我不知道哪个适合西班牙语,但你应该知道 ;-)

这是您的代码和 UTF-8 的示例:

$email_headers  = "From: $name <$email>\r\n";
$email_headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";