PHP电子邮件与西班牙语口音错误显示

时间:2015-01-15 19:26:53

标签: php email

我的网站是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.";
}

&GT;

1 个答案:

答案 0 :(得分:0)

尝试在电子邮件标头中设置编码 (我不知道西班牙语哪个是正确的,但你可以这么做; - )

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

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