Wordpress主题和非英语标志上的联系表格(utf-8)


Contact Form on Wordpress Theme and Non-English Signs (utf-8)

Wordpress Theme中已经内置了一个联系表单。

它位于页面底部 nikosis.mzonespace.co.uk

它工作正常,除了非英语标志外,它还将所有内容正确发送到一封好的电子邮件。当您想键入 ą、ę、ć、ź、ł、ó 等符号时,只有问号。

所以它看起来像这样:?, ?, ?, ?, ?, ?.

如何让它工作?我努力了一两个小时,但找不到解决方案。

这是联系表单的代码:

<?php 
$st_url = dirname(__FILE__);
if ( preg_match('#wp-content#isU', $st_url) ) {
    $path_to_file = explode('wp-content', $st_url);
    $path_to_wp = $path_to_file[0];
    require_once  $path_to_wp .'/wp-load.php';  
}
else {
    require_once '../../../../../../wp-load.php';  
}
function valid_email($str)
{
    return ( ! preg_match("/^([a-z0-9'+_'-]+)('.[a-z0-9'+_'-]+)*@([a-z0-9'-]+'.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if ( isset($_POST) )
{
    $_POST = array_map('trim', $_POST);
    $contact_name = stripslashes($_POST['fullname']);
    $contact_email = stripslashes($_POST['email']);
    $persons_attending = stripslashes($_POST['persons_attending']);
    $wedding_ceremony = stripslashes($_POST['wedding_ceremony']);
    $regex_email = "/^([a-z0-9'+_'-]+)('.[a-z0-9'+_'-]+)*@([a-z0-9'-]+'.)+[a-z]{2,6}$/ix";
    if ( empty($contact_name) ) {
        $halt[] = __('Please enter your name.', 'beau');
    }
    if ( empty($contact_email) ) {
        $halt[] = __('Please enter your email.', 'beau');
    }
    elseif ( !valid_email($contact_email) ) {
        $halt[] = __('Please enter a valid email address.', 'beau');
    }
//  td

    if ( isset($halt) )
    {
        echo '<div class="st-message error">';
        echo '<a href="#" class="close" data-dismiss="alert">&times;</a>';
        echo @implode('<br />', $halt);
        echo '</div>';
    }
    else {
        $messages = '
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head></head>
        <body>
        <table>
            <tr><td valign="top"><b>'. __('Name', 'beau') .'</b></td><td valign="top">' . $contact_name . '</td></tr>
            <tr><td valign="top"><b>'. __('Email', 'beau') .'</b></td><td valign="top">' . $contact_email . '</td></tr>
            <tr><td valign="top"><b>'. __('Subject', 'beau') .'</b></td><td valign="top">' . $contact_subject . '</td></tr>
            <tr><td valign="top"><b>'. __('Message', 'beau')  .'</b></td><td valign="top"></td></tr>
            <tr><td valign="top" colspan="2"><td valign="top">' . $contact_message . '</td></tr>
        </table>
        </body>
        </html>';
        $headers = "MIME-Version: 1.0" . "'r'n";
        $headers .= "Content-type:text/html;charset=iso-8859-1" . "'r'n";
        $headers .= "From: " . stripslashes($contact_name) . " <" . $contact_email . ">" . "'r'n";
        $headers .= "Sender-IP: " . $_SERVER["SERVER_ADDR"] . "'r'n";
        $headers .= "Priority: normal" . "'r'n";
        $headers .= "X-Mailer: PHP/" . phpversion();
        $body = utf8_decode($messages);
        if(!empty($_POST['send_to'])){
            $to = $_POST['send_to'];
        }else{
            $to=of_get_option('contact_email');
        }
        $subject = __('Contact Email From', 'beau') .': '. $contact_name;
        if ( wp_mail( $to, $subject, $body, $headers ) )
        {
            echo '<div class="st-message success">';
            echo '<a href="#" class="close" data-dismiss="alert">&times;</a>';
            echo of_get_option('contact_success', 'Your form has been submitted successfully! Thank you!');
            echo '</div>';
        }
        else
        {
            echo '<div class="st-message error">';
            echo '<a href="#" class="close" data-dismiss="alert">&times;</a>';
            echo 'Something went wrong!';
            echo '</div>';
        }
    }
}

这是我的代码,我添加了一些修改。我上次得到的这个是根文件。

不过,它不起作用:

    <?php 
    $st_url = dirname(__FILE__);
    if ( preg_match('#wp-content#isU', $st_url) ) {
        $path_to_file = explode('wp-content', $st_url);
        $path_to_wp = $path_to_file[0];
        require_once  $path_to_wp .'/wp-load.php';  
    }
    else {
        require_once '../../../../../../wp-load.php';  
    }
    function valid_email($str)
    {
        return ( ! preg_match("/^([a-z0-9'+_'-]+)('.[a-z0-9'+_'-]+)*@([a-z0-9'-]+'.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
    }
    if ( isset($_POST) )
    {
        $_POST = array_map('trim', $_POST);
        $contact_name = stripslashes($_POST['fullname']);
        $contact_email = stripslashes($_POST['email']);
        $persons_attending = stripslashes($_POST['persons_attending']);
        $wedding_ceremony = stripslashes($_POST['wedding_ceremony']);
        $regex_email = "/^([a-z0-9'+_'-]+)('.[a-z0-9'+_'-]+)*@([a-z0-9'-]+'.)+[a-z]{2,6}$/ix";
        if ( empty($contact_name) ) {
            $halt[] = __('Please enter your name.', 'beau');
        }
        if ( empty($contact_email) ) {
            $halt[] = __('Please enter your email.', 'beau');
        }
        elseif ( !valid_email($contact_email) ) {
            $halt[] = __('Please enter a valid email address.', 'beau');
        }
    //  td

        if ( isset($halt) )
        {
            echo '<div class="st-message error">';
            echo '<a href="#" class="close" data-dismiss="alert">&times;</a>';
            echo @implode('<br />', $halt);
            echo '</div>';
        }
        else {
            $messages = '
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            <html>
            <head><meta http-equiv="Content-Type"  content="text/html charset=UTF-8" /></head>
            <body>
            <table>
                <tr><td valign="top"><b>'. __('Name', 'beau') .'</b></td><td valign="top">' . $contact_name . '</td></tr>
                <tr><td valign="top"><b>'. __('Email', 'beau') .'</b></td><td valign="top">' . $contact_email . '</td></tr>
                <tr><td valign="top"><b>'. __('Subject', 'beau') .'</b></td><td valign="top">' . $persons_attending . '</td></tr>
                <tr><td valign="top"><b>'. __('Message', 'beau')  .'</b></td><td valign="top"></td></tr>
                <tr><td valign="top" colspan="2"><td valign="top">' . $wedding_ceremony . '</td></tr>
            </table>
            </body>
            </html>';
            $headers = "MIME-Version: 1.0" . "'r'n";
            $headers .= "Content-type:text/html;charset=utf-8" . "'r'n";
            $headers .= "From: " . stripslashes($contact_name) . " <" . $contact_email . ">" . "'r'n";
            $headers .= "Sender-IP: " . $_SERVER["SERVER_ADDR"] . "'r'n";
            $headers .= "Priority: normal" . "'r'n";
            $headers .= "X-Mailer: PHP/" . phpversion();
            $body = utf8_decode($messages);
            if(!empty($_POST['send_to'])){
                $to = $_POST['send_to'];
            }else{
                $to=of_get_option('contact_email');
            }
            $subject = __('Contact Email From', 'beau') .': '. $contact_name;
            if ( wp_mail( $to, $subject, $body, $headers ) )
            {
                echo '<div class="st-message success">';
                echo '<a href="#" class="close" data-dismiss="alert">&times;</a>';
                echo of_get_option('contact_success', 'Your form has been submitted successfully! Thank you!');
                echo '</div>';
            }
            else
            {
                echo '<div class="st-message error">';
                echo '<a href="#" class="close" data-dismiss="alert">&times;</a>';
                echo 'Something went wrong!';
                echo '</div>';
            }
        }
    }

添加 UTF-8 元标头,

<meta http-equiv="Content-Type"  content="text/html charset=UTF-8" /> (Or)
$headers=array("Content-Type: text/html; charset=UTF-8");