Поддержка Проблемы и решения Проблема с кодировкой почты!!! ПОМОГИТЕ!!!

  • Помогите… Бьюсь уже неделю. На почту вместо русских букв приходят такие иероглифы:

    Name: п п я п п
    Email: 11@mail.ru
    Message: п я п я я п

    PHP код:

    <?php if (get_option(’email_form’) == «yes» || get_option(’email_form’) == «») { ?>
    <div class=»email_form»>
    <h3><?php _e(‘Contact Ad Owner’,’cp’); ?></h3>
    <?php

    $email_err = «»;
    $email_ok = «»;
    if (isset($_POST[‘action’]) && $_POST[‘action’] == ’email’) {
    $subject2 = «Re: «.get_the_title();
    $name2 = strip_tags($_POST[‘name2’]);
    $email2 = strip_tags($_POST[’email2′]);
    $receiver_email = strip_tags($_POST[‘receiver_email’]);
    $receiver_email = str_replace(«gd6j83ksl», «@», $receiver_email);
    $receiver_email = str_replace(«m3gd0374h», «.», $receiver_email);
    $message2 = strip_tags($_POST[‘message2’]);

    if ( $name2 == «») {
    $email_err .= __(‘Enter your name’,’cp’) . «
    «;
    }

    if ( $email2 == «») {
    $email_err .= __(‘Enter your email address’,’cp’) . «
    «;
    } else {
    if ( !cp_check_email($email2) ) {
    $email_err .= __(‘Email format is incorrect’,’cp’) . «
    «;
    }
    }

    if ( $message2 == «») {
    $email_err .= __(‘Enter a message’,’cp’) . «
    «;
    }

    $email_total = (int)$_POST[’email_total’];
    $email_nr1 = (int)$_POST[’email_nr1′]; $email_nr1 = str_replace(«60293», «», $email_nr1);
    $email_nr2 = (int)$_POST[’email_nr2′]; $email_nr2 = str_replace(«36202», «», $email_nr2);
    $email_nr1nr2 = $email_nr1 + $email_nr2;

    if ( $email_total != $email_nr1nr2 ) {
    $email_err .= __(‘The spam field is incorrect’,’cp’) . «
    «;
    }

    if ( $email_err == «») {
    $body = __(‘Someone is interested in your classified ad! They sent you a message from the following page:’,’cp’) . «\n\n» . selfURL().»
    \n
    Name: $name2
    Email: $email2
    Message: $message2
    «;
    // $receiver_email = «tester@localhost»; //uncomment this line to test locally
    // ini_set(‘sendmail_from’, ‘me@domain.com’); //this line might need to be enabled for some people using Windows hosted sites
    mail($receiver_email,$subject2,$body,»From: $email2″);
    $email_ok = «ok»;
    unset($receiver_email, $name2, $email2, $message2, $subject2);

    }
    }
    ?>

    <?php
    if ( $email_err != «» ) {
    echo «<div class=\»email_err\»>$email_err</div>»;
    }
    ?>
    <?php
    if ( $email_ok == «ok» ) {
    echo «<div class=\»email_ok\»>» . __(‘Your email has been sent.’,’cp’) . «</div>»;
    }
    ?>

    <?php if (get_option(‘expand_email_form’) == «yes» ) { ?>
    <div id=»email_form_data»>
    <?php } else { ?>
    <div id=»email_form_data» <?php if ($email_err == «») { echo «style=\»display: none;\»»; } ?>>
    <?php } ?>

    <form action=»<?php the_permalink(); ?>#email-form» method=»post»>
    <?php _e(‘Name’,’cp’); ?>:
    <input type=»text» name=»name2″ value=»<?php echo $name2;?>» />
    <?php _e(‘Email’,’cp’); ?>:
    <input type=»text» name=»email2″ value=»<?php echo $email2;?>» />
    <?php _e(‘Subject’,’cp’); ?>:
    <div class=»like_input»><?php _e(‘Re:’,’cp’); ?> <?php the_title(); ?></div>
    <?php _e(‘Message’,’cp’); ?>:
    <textarea name=»message2″ rows=»1″ cols=»2″><?php echo $message2;?></textarea>
    <input type=»hidden» name=»action» value=»email» />
    <input type=»hidden» name=»receiver_email» value=»<?php email_spam(get_post_meta($post->ID, «email», true)); ?>» />
    <div class=»capcha» style=»text-align: center;»>
    <?php
    $email_nr1 = rand(«0», «9»);
    $email_nr2 = rand(«0», «9»);
    ?>
    <?php echo $email_nr1; ?> + <?php echo $email_nr2; ?> = <input type=»text» name=»email_total» class=»email_captcha» maxlength=»2″ value=»» />  
    <input type=»hidden» name=»email_nr1″ value=»60293<?php echo $email_nr1; ?>» />
    <input type=»hidden» name=»email_nr2″ value=»36202<?php echo $email_nr2; ?>» />
    </div>
    <input type=»submit» style=»width:240px;» name=»send» value=»<?php _e(‘Send Email’,’cp’); ?>» />
    </form>
    </div>
    </div>
    <?php } ?>

    Очень надеюсь на помощь…

Просмотр 9 ответов — с 1 по 9 (всего 9)
  • Atrax

    (@atrax)

    Ethical engineer

    Спасибо за ответ, но можно немного поподробней, где именно прописать нужную кодировку. Просто очень плохо разбираюсь в PHP.

    Найдите
    mail($receiver_email,$subject2,$body,"From: $email2");
    Замените на:

    $headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
    $header .= 'From: $email2';
    mail($receiver_email,$subject2,$body,$headers);

    Спасибо slaFFik!!! Всё получилось!!! Русские буква стали отображаться. Но в письме не отображаются мэйл автора, тема сообщения и ссылка на страницу, с которого прислано сообщение неактивная. Не подскажите как доработать эти недочёты. Очень рассчитываю на помощь!!!

    Почти уверен, что вы не туда вставили. Случайно не после вот это строки:
    unset($receiver_email, $name2, $email2, $message2, $subject2);
    Но я опечатку у себя еще увидел. Вот это надо вставить:

    $headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: $email2';
    mail($receiver_email,$subject2,$body,$headers);

    Вместо того, что вы уже вставили.

    Как ни странно даже изменив опечатку ничего не изменилось. На почту письмо приходит с пустой графой «Тема» с мейлом хостинга и неактивной ссылкой на страницу автора…. Вот код формы. Я жирным цветом отметил код который исправил… Заранее спасибо за помощь

    <?php if (get_option('email_form') == "yes" || get_option('email_form') == "") { ?>
    <div class="email_form">
    <h3><a href="#"><?php _e('Написать автору','cp'); ?></a></h3>
    <?php
    
    $email_err = "";
    $email_ok = "";
    if (isset($_POST['action']) && $_POST['action'] == 'email') {
    $subject2 = "Re: ".get_the_title();
    $name2 = strip_tags($_POST['name2']);
    $email2 = strip_tags($_POST['email2']);
    $receiver_email = strip_tags($_POST['receiver_email']);
    $receiver_email = str_replace("gd6j83ksl", "@", $receiver_email);
    $receiver_email = str_replace("m3gd0374h", ".", $receiver_email);
    $message2 = strip_tags($_POST['message2']);
    
    if ( $name2 == "") {
    $email_err .= __('Введите своё имя','cp') . "";
    }
    
    if ( $email2 == "") {
    $email_err .= __('Введите свой email','cp') . "";
    } else {
    if ( !cp_check_email($email2) ) {
    $email_err .= __('Email адрес не корректный','cp') . "";
    }
    }
    
    if ( $message2 == "") {
    $email_err .= __('Напишите текст сообщения','cp') . "";
    }
    
    $email_total = (int)$_POST['email_total'];
    $email_nr1 = (int)$_POST['email_nr1']; $email_nr1 = str_replace("60293", "", $email_nr1);
    $email_nr2 = (int)$_POST['email_nr2']; $email_nr2 = str_replace("36202", "", $email_nr2);
    $email_nr1nr2 = $email_nr1 + $email_nr2;
    
    if ( $email_total != $email_nr1nr2 ) {
    $email_err .= __('Пример решён не верно','cp') . "";
    }
    
    if ( $email_err == "") {
    $body = __('Ответ на Ваше объявление! Письмо прислано со страницы Вашего объявления: ','cp') . "\n\n" . selfURL()."
    \n
    Имя: $name2
    Email: $email2
    Сообщение: $message2
    ";
    // $receiver_email = "tester@localhost"; //uncomment this line to test locally
    // ini_set('sendmail_from', 'me@domain.com'); //this line might need to be enabled for some people using Windows hosted sites
    $headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: $email2';
    mail($receiver_email,$subject2,$body,$headers);
    
    $email_ok = "ok";
    unset($receiver_email, $name2, $email2, $message2, $subject2);
    
    }
    }
    ?>
    <a></a>
    <?php
    if ( $email_err != "" ) {
    echo "<div class=\"email_err\">$email_err</div>";
    }
    ?>
    <?php
    if ( $email_ok == "ok" ) {
    echo "<div class=\"email_ok\">" . __('Ваше сообщение отправлено.','cp') . "</div>";
    }
    ?>
    
    <?php if (get_option('expand_email_form') == "yes" ) { ?>
    <div id="email_form_data">
    <?php } else { ?>
    <div id="email_form_data" <?php if ($email_err == "") { echo "style=\"display: none;\""; } ?>>
    <?php } ?>
    
    <form action="<?php the_permalink(); ?>#email-form" method="post">
    <?php _e('Имя','cp'); ?>:<input type="text" name="name2" value="<?php echo $name2;?>" />
    <?php _e('Email','cp'); ?>:<input type="text" name="email2" value="<?php echo $email2;?>" />
    <?php _e('Тема','cp'); ?>:
    <div class="like_input"><?php _e('Re:','cp'); ?> <?php the_title(); ?></div>
    <?php _e('Сообщение','cp'); ?>:<textarea name="message2" rows="1" cols="2"><?php echo $message2;?></textarea>
    <input type="hidden" name="action" value="email" />
    <input type="hidden" name="receiver_email" value="<?php email_spam(get_post_meta($post->ID, "email", true)); ?>" />
    <div class="capcha" style="text-align: center;">
    <?php
    $email_nr1 = rand("0", "9");
    $email_nr2 = rand("0", "9");
    ?>
    <?php echo $email_nr1; ?> + <?php echo $email_nr2; ?> = <input type="text" name="email_total" class="email_captcha" maxlength="2" value="" /> &nbsp;
    <input type="hidden" name="email_nr1" value="60293<?php echo $email_nr1; ?>" />
    <input type="hidden" name="email_nr2" value="36202<?php echo $email_nr2; ?>" />
    </div>
    <input type="submit" style="width:240px;" name="send" value="<?php _e('Отправить сообщение','cp'); ?>" />
    </form>
    </div>
    </div>
    <?php } ?>
    Atrax

    (@atrax)

    Ethical engineer

    $headers .= 'From: $email2';
    А кавычки разве не двойные?
    Внутри одиночных переменные вроде не подставляются…

    Спасибо подправил. Мейл отправителя стал работать. НЕ работает толко ТЕМА письма и ССЫЛКА на страницу. С чем это может быть связано?

    Anton1987
    Вообще-то вы открыли тему про кодировку почты — и проблема решена.. А почему не работают — я не вижу ошибку, тестировать — нет времени.

    Atrax,
    Да, спасибо, я был невнимателен.

Просмотр 9 ответов — с 1 по 9 (всего 9)
  • Тема «Проблема с кодировкой почты!!! ПОМОГИТЕ!!!» закрыта для новых ответов.