Поддержка Проблемы и решения Форма обратной связи — кракозябры!

  • При отправке писем через форму обратной связи приходят иероглифы. Возможно, что-то недописано в шаблоне обратной формы. Там всего три поля: Имя, email, сообщение. Как задать им нужную кодировку??

    Есть еще файл class-phpmailer.php, но, вроде бы, письма отправляются не через него, т.к. они приходят даже если его удалить! Какой еще файл может отвечать за отправку сообщений из формы обратной связи?

    Вот код этой формы:

    <?php
    /*
    Template Name: Contact
    */
    if(isset($_POST['submitted'])) {
    		//Check to make sure that the name field is not empty
    		if(trim($_POST['contactName']) === '') {
    			$nameError = __("You forgot to enter your name.", "site5framework");
    			$hasError = true;
    		} else {
    			$name = trim($_POST['contactName']);
    		}
    
    		//Check to make sure sure that a valid email address is submitted
    		if(trim($_POST['email']) === '')  {
    			$emailError = __("You forgot to enter your email address.", "site5framework");
    			$hasError = true;
    		} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
    			$emailError = __("You entered an invalid email address.", "site5framework");
    			$hasError = true;
    		} else {
    			$email = trim($_POST['email']);
    		}
    
    		//Check to make sure message were entered
    		if(trim($_POST['message']) === '') {
    			$messageError = __("You forgot to enter your message.", "site5framework");
    			$hasError = true;
    		} else {
    			if(function_exists('stripslashes')) {
    				$message = stripslashes(trim($_POST['message']));
    			} else {
    				$message = trim($_POST['message']);
    			}
    		}
    
    		//If there is no error, send the email
    		if(!isset($hasError)) {
    			$msg .= "------------User Info------------ \r\n"; //Title
    			$msg .= "User IP : ".$_SERVER["REMOTE_ADDR"]."\r\n"; //Sender's IP
    			$msg .= "Browser Info : ".$_SERVER["HTTP_USER_AGENT"]."\r\n"; //User agent
    			$msg .= "User Come From : ".$_SERVER["HTTP_REFERER"]; //Referrer
    
    			$emailTo = ''.of_get_option('veecard_contact_email').'';
    			$subject = 'Contact Form Submission From '.$name;
    			$body = "Name: $name \n\nEmail: $email \n\nMessage: $message \n\n $msg";
    			$headers = 'From: '.get_bloginfo('name').' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
    
    			if(mail($emailTo, $subject, $body, $headers)) $emailSent = true;
    
    	}
    
    }
    get_header();
    ?>
    
             <article>
    
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    			<header>
    				<h1><?php the_title(); ?></h1>
    			</header>
    
    			<section>
    			<?php the_content(); ?>
    			<?php endwhile; endif;?>
    
    			<p class="error" <?php if($hasError != '') echo 'style="display:block;"'; ?>><?php _e('There was an error submitting the form.', 'site5framework'); ?></p>
    
    			<p class="thanks"><?php _e('<strong>Thanks!</strong> Your email was successfully sent. We should be in touch soon.', 'site5framework'); ?></p>
    
    			<!-- contact form -->
    			<form id="contactform" method="POST">
                     <div class="form-row">
                         <div class="input col_half first">
                             <label for="name"><?php _e("Name", "site5framework"); ?><sup>*</sup></label>
                             <input type="text" id="name" name="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField"/>
    				<span class="error" <?php if($nameError != '') echo 'style="display:block;"'; ?>><?php _e("You forgot to enter your name.", "site5framework");?></span>
                         </div>
                         <div class="input col_half">
                             <label for="email"><?php _e("Email", "site5framework"); ?><sup>*</sup></label>
                             <input type="text" id="email" name="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="requiredField email"/>
    				  <span class="error" <?php if($emailError != '') echo 'style="display:block;"'; ?>><?php _e("You forgot to enter your email address.", "site5framework");?></span>
                         </div>
                     </div>
                     <div class="form-row">
                         <div class="input textarea">
                             <label for="message"><?php _e("Message", "site5framework"); ?><sup>*</sup></label>
                             <textarea cols="20" rows="7" id="message" name="message" class="requiredField"><?php if(isset($_POST['message'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['message']); } else { echo $_POST['message']; } } ?></textarea>
    				  <span class="error" <?php if($messageError != '') echo 'style="display:block;"'; ?>><?php _e("You forgot to enter your message.", "site5framework");?></span>
                         </div>
                     </div>
                     <div class="form-row">
    					<input type="hidden" name="submitted" id="submitted" value="true" />
    					<input type="submit" value="<?php _e('Send', 'site5framework'); ?>" class="modern socle" />
                     </div>
                 </form>
                 <!-- end contact form -->
    
    		</section>
    	</article>
    
    <?php get_footer(); ?>
Просмотр 4 ответов — с 1 по 4 (всего 4)
  • Возможно, что-то недописано в шаблоне обратной формы

    charset

    Автор dr.grotesque

    (@drgrotesque)

    Это я догадался. А КАК и где прописать-то, чтобы кракозябры не слал??

    А КАК и где прописать-то, чтобы кракозябры не слал??

    В $headers
    См примеры по ссылке.

    Автор dr.grotesque

    (@drgrotesque)

    Если Вы имеете ввиду: $headers .= ‘Content-type: text/html; charset=utf-8’ . «\r\n»;
    То я весь день и так и сяк пытаюсь это прописать, но результат НОЛЬ. Пожалуйста, напишите мне эту заветную строчку полностью и скажите, куда ее вставлять?!

Просмотр 4 ответов — с 1 по 4 (всего 4)
  • Тема «Форма обратной связи — кракозябры!» закрыта для новых ответов.