За последние 24 часа нас посетили 22656 программистов и 1015 роботов. Сейчас ищут 719 программистов ...

Форма обратной связи

Тема в разделе "Сделайте за меня", создана пользователем Arina, 21 июн 2017.

  1. Arina

    Arina Новичок

    С нами с:
    21 июн 2017
    Сообщения:
    13
    Симпатии:
    0
    Привет всем!
    Может кто нибудь поможет?
    Есть сайт на вордпресс, не работает обратная связь

    Страница контактов


    PHP:
    1. <?php
    2. /*
    3. Template Name: Contact page
    4. */
    5. get_header();
    6. ?>
    7.  
    8. <section id="content" class="nopadtop">
    9.         <?php if(iwebtheme_smof_data('map_enable') != 0) { ?>
    10.             <div id="googlemaps" class="google-map">
    11.             </div>      
    12.         <?php } ?>
    13.        
    14. <div class="container">
    15.     <div class="row">
    16.     <div class="col-lg-12">
    17.     <div class="col-lg-8 col-md-offset-77">
    18.  
    19. <div class="content_item">
    20. <div class="form_settings">
    21.  
    22.  
    23.     <div class=" col-md-offset-77">
    24.     <h1 align="center"><?php the_title(); ?></h1>
    25.         <h2 align="center"><?php echo __('Свяжитесь с нами, заполнив контактную форму','iwebtheme'); ?></h2>
    26.  
    27.                 <form action="<?php the_permalink(); ?>" id="contactform" method="post" class="validateform">
    28.  
    29.                     <div class="row">
    30.                        
    31.                             <p><input type="text" class="requiredField" name="contactName" id="contactName" placeholder="* <?php echo __('Введите ваше имя','iwebtheme'); ?>" data-rule="maxlen:4" data-msg="<?php echo __('Пожалуйста, введите не менее 4 символов','iwebtheme'); ?>" />
    32.                             <div class="validation">
    33.                             </div></p>
    34.                        
    35.                        
    36.                        
    37.                             <p><input type="text" class="requiredField" name="email" id="email" placeholder="* <?php echo __('Введите e-mail','iwebtheme'); ?>" data-rule="email" data-msg="<?php echo __('Не верный email адрес','iwebtheme'); ?>" />
    38.                             <div class="validation">
    39.                             </div></p>
    40.                        
    41.                        
    42.                        
    43.                             <p><input type="text" name="subject" id="subject" placeholder="<?php echo __('Введите тему','iwebtheme'); ?>" data-rule="maxlen:4" data-msg="<?php echo __('Пожалуйста, введите не менее 4 символов','iwebtheme'); ?>" />
    44.                             <div class="validation">
    45.                             </div></p>
    46.                    
    47.                        
    48.                    
    49.                             <p><textarea rows="12" name="comments" class="requiredField" id="comments" class="input-block-level" placeholder="* <?php echo __('Введите сообщение','iwebtheme'); ?>..." data-rule="required" data-msg="<?php echo __('Пожалуйста, напишите что-нибудь','iwebtheme'); ?>"></textarea>
    50.                             <div class="validation clearfix">
    51.                             </div></p>
    52.                
    53.                         <div class="col-lg-12 field">
    54.                             <p>
    55.                                 <button name="Mysubmitted" id="Mysubmitted" class="btn btn-theme margintop20 pull-left" type="submit"><?php echo __('Отправить','iwebtheme'); ?></button>
    56.                                 <span class="pull-right margintop20">* <?php echo __('Пожалуйста, заполните все необходимые поля','iwebtheme'); ?>!</span>
    57.                             </p>
    58.                             <input type="hidden" name="submitted" id="submitted" value="true" />
    59.                             <input type="hidden" name="contact_success" id="contact_success" value="<?php echo iwebtheme_smof_data('contact_success');?>" />
    60.                         </div>                  
    61.                     </div>
    62.                    
    63.                 </form>
    64.  
    65.    
    66.     </div>
    67.     </div>
    68. </div>
    69.  
    70. </form>
    71.  
    72.  
    73. </div>
    74. </div></div>
    75.    
    76.     </div>
    77.     </div>
    78. </div>
    79. </section>
    80. <?php
    81. get_template_part('includes/contact-function');
    82. ?>  
    83. <?php get_footer(); ?>
    contact-function.php

    PHP:
    1. <?php
    2. global $redux_iwebtheme;
    3. $contact_email = $redux_iwebtheme['con-email'];
    4. $nameError ='';
    5. $emailError ='';
    6. $commentError = '';
    7.  
    8. //If the form is submitted
    9. if(isset($_POST['submitted'])) {
    10.         //Check to make sure that the name field is not empty
    11.         if(trim($_POST['contactName']) === '') {
    12.             $nameError = 'You forgot to enter your name.';
    13.             $hasError = true;
    14.         } else {
    15.             $name = trim($_POST['contactName']);
    16.         }
    17.        
    18.         //Check to make sure sure that a valid email address is submitted
    19.         if(trim($_POST['contactMail']) === '')  {
    20.             $emailError = 'You forgot to enter your email address.';
    21.             $hasError = true;
    22.         } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['contactMail']))) {
    23.             $emailError = 'You entered an invalid email address.';
    24.             $hasError = true;
    25.         } else {
    26.             $email = trim($_POST['contactMail']);
    27.         }
    28.  
    29.            
    30.         //Check to make sure comments were entered  
    31.         if(trim($_POST['contactMessage']) === '') {
    32.             $commentError = 'You forgot to enter your message.';
    33.             $hasError = true;
    34.         } else {
    35.             if(function_exists('stripslashes')) {
    36.                 $comments = stripslashes(trim($_POST['contactMessage']));
    37.             } else {
    38.                 $comments = trim($_POST['contactMessage']);
    39.             }
    40.         }
    41.            
    42.         //If there is no error, send the email
    43.         if(!isset($hasError)) {
    44.  
    45.             $emailTo = $contact_email;
    46.             $subject = "New message";
    47.             $sendCopy = trim($_POST['sendCopy']);
    48.             $body = "Name: $name \n\nEmail: $email \n\nMessage: $comments";
    49.             $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
    50.            
    51.             wp_mail($emailTo, $subject, $body, $headers);
    52.  
    53.             if($sendCopy == true) {
    54.                 $subject = '[Copy] your submission';
    55.                 $headers = 'From: '.$contact_email;
    56.                 wp_mail($email, $subject, $body, $headers);
    57.             }
    58.  
    59.             $emailSent = true;
    60.  
    61.         }
    62. } ?>
    Чего не хватает?
     
  2. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.553
    Симпатии:
    631
    Возможно, в скрипте ошибка, а сообщение об ошибке не видно.
    http://phpfaq.ru/debug как увидеть ошибки
     
  3. Arina

    Arina Новичок

    С нами с:
    21 июн 2017
    Сообщения:
    13
    Симпатии:
    0
    Выходит что сообщение отправлено, но не доходят письма

    Сайт https://selempi.ru
     
  4. Arina

    Arina Новичок

    С нами с:
    21 июн 2017
    Сообщения:
    13
    Симпатии:
    0
    Привет всем!
    Может кто нибудь поможет?
    Есть сайт на вордпресс, не работает обратная связь
    PHP:
    1. <?php
    2. /*
    3. Template Name: Contact page
    4. */
    5. get_header();
    6. ?>
    7. <section id="content" class="nopadtop">
    8.         <?php if(iwebtheme_smof_data('map_enable') != 0) { ?>
    9.             <div id="googlemaps" class="google-map">
    10.             </div>    
    11.         <?php } ?>
    12.      
    13. <div class="container">
    14.     <div class="row">
    15.     <div class="col-lg-12">
    16.     <div class="col-lg-8 col-md-offset-77">
    17. <div class="content_item">
    18. <div class="form_settings">
    19.     <div class=" col-md-offset-77">
    20.     <h1 align="center"><?php the_title(); ?></h1>
    21.         <h2 align="center"><?php echo __('Свяжитесь с нами, заполнив контактную форму','iwebtheme'); ?></h2>
    22.                 <form action="<?php the_permalink(); ?>" id="contactform" method="post" class="validateform">
    23.                     <div class="row">
    24.                      
    25.                             <p><input type="text" class="requiredField" name="contactName" id="contactName" placeholder="* <?php echo __('Введите ваше имя','iwebtheme'); ?>" data-rule="maxlen:4" data-msg="<?php echo __('Пожалуйста, введите не менее 4 символов','iwebtheme'); ?>" />
    26.                             <div class="validation">
    27.                             </div></p>
    28.                      
    29.                      
    30.                      
    31.                             <p><input type="text" class="requiredField" name="email" id="email" placeholder="* <?php echo __('Введите e-mail','iwebtheme'); ?>" data-rule="email" data-msg="<?php echo __('Не верный email адрес','iwebtheme'); ?>" />
    32.                             <div class="validation">
    33.                             </div></p>
    34.                      
    35.                      
    36.                      
    37.                             <p><input type="text" name="subject" id="subject" placeholder="<?php echo __('Введите тему','iwebtheme'); ?>" data-rule="maxlen:4" data-msg="<?php echo __('Пожалуйста, введите не менее 4 символов','iwebtheme'); ?>" />
    38.                             <div class="validation">
    39.                             </div></p>
    40.                  
    41.                      
    42.                  
    43.                             <p><textarea rows="12" name="comments" class="requiredField" id="comments" class="input-block-level" placeholder="* <?php echo __('Введите сообщение','iwebtheme'); ?>..." data-rule="required" data-msg="<?php echo __('Пожалуйста, напишите что-нибудь','iwebtheme'); ?>"></textarea>
    44.                             <div class="validation clearfix">
    45.                             </div></p>
    46.              
    47.                         <div class="col-lg-12 field">
    48.                             <p>
    49.                                 <button name="Mysubmitted" id="Mysubmitted" class="btn btn-theme margintop20 pull-left" type="submit"><?php echo __('Отправить','iwebtheme'); ?></button>
    50.                                 <span class="pull-right margintop20">* <?php echo __('Пожалуйста, заполните все необходимые поля','iwebtheme'); ?>!</span>
    51.                             </p>
    52.                             <input type="hidden" name="submitted" id="submitted" value="true" />
    53.                             <input type="hidden" name="contact_success" id="contact_success" value="<?php echo iwebtheme_smof_data('contact_success');?>" />
    54.                         </div>                
    55.                     </div>
    56.                  
    57.                 </form>
    58.  
    59.     </div>
    60.     </div>
    61. </div>
    62. </form>
    63. </div>
    64. </div></div>
    65.  
    66.     </div>
    67.     </div>
    68. </div>
    69. </section>
    70. <?php
    71. get_template_part('includes/contact-function');
    72. ?>
    73. <?php get_footer(); ?>
    contact-function.php

    PHP:
    1. <?php
    2. global $redux_iwebtheme;
    3. $contact_email = $redux_iwebtheme['con-email'];
    4. $nameError ='';
    5. $emailError ='';
    6. $commentError = '';
    7. //If the form is submitted
    8. if(isset($_POST['submitted'])) {
    9.         //Check to make sure that the name field is not empty
    10.         if(trim($_POST['contactName']) === '') {
    11.             $nameError = 'You forgot to enter your name.';
    12.             $hasError = true;
    13.         } else {
    14.             $name = trim($_POST['contactName']);
    15.         }
    16.      
    17.         //Check to make sure sure that a valid email address is submitted
    18.         if(trim($_POST['contactMail']) === '')  {
    19.             $emailError = 'You forgot to enter your email address.';
    20.             $hasError = true;
    21.         } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['contactMail']))) {
    22.             $emailError = 'You entered an invalid email address.';
    23.             $hasError = true;
    24.         } else {
    25.             $email = trim($_POST['contactMail']);
    26.         }
    27.          
    28.         //Check to make sure comments were entered
    29.         if(trim($_POST['contactMessage']) === '') {
    30.             $commentError = 'You forgot to enter your message.';
    31.             $hasError = true;
    32.         } else {
    33.             if(function_exists('stripslashes')) {
    34.                 $comments = stripslashes(trim($_POST['contactMessage']));
    35.             } else {
    36.                 $comments = trim($_POST['contactMessage']);
    37.             }
    38.         }
    39.          
    40.         //If there is no error, send the email
    41.         if(!isset($hasError)) {
    42.             $emailTo = $contact_email;
    43.             $subject = "New message";
    44.             $sendCopy = trim($_POST['sendCopy']);
    45.             $body = "Name: $name \n\nEmail: $email \n\nMessage: $comments";
    46.             $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
    47.          
    48.             wp_mail($emailTo, $subject, $body, $headers);
    49.             if($sendCopy == true) {
    50.                 $subject = '[Copy] your submission';
    51.                 $headers = 'From: '.$contact_email;
    52.                 wp_mail($email, $subject, $body, $headers);
    53.             }
    54.             $emailSent = true;
    55.         }
    56. } ?>
    не отправляет письмо
     
  5. RyF

    RyF Новичок

    С нами с:
    13 июл 2017
    Сообщения:
    12
    Симпатии:
    4
    Вы сообщения с хостинга отправляете? Функция mail() будет работать только на реальном сервере)
     
  6. Arina

    Arina Новичок

    С нами с:
    21 июн 2017
    Сообщения:
    13
    Симпатии:
    0
    Спасибо за отклик! Да, с платного хостинга, раньше работал, но только Яндекс почтой. Если Вам не сложно, помогите с ошибкой.
     
  7. RyF

    RyF Новичок

    С нами с:
    13 июл 2017
    Сообщения:
    12
    Симпатии:
    4
    Должно быть что-то вроде этого:
    PHP:
    1. <?php
    2.     if($_POST['send_email']){
    3.         $name_from = htmlspecialchars(trim($_POST['name']));
    4.         $from  = htmlspecialchars(trim($_POST['email']));
    5.         $text_message = htmlspecialchars(trim($_POST['message']));
    6.         $headers = 'From: webmaster@example.com' . "\r\n" .
    7.             'Reply-To: ryf-tester@yandex.ru' . "\r\n" .
    8.             'X-Mailer: PHP/' . phpversion();
    9.  
    10.         $to = 'ryf-tester@yandex.ru';
    11.  
    12.         if($name_from != null && $text_message != null && $from != null){
    13.             $message = 'Сообщение от ' . $from .' ' . $text_message;
    14.             mail($to, $name_from, $message, $headers);
    15.         }else{
    16.             echo 'Вы не заполнили поле!';
    17.         }
    18.     }
    19. ?>
    20. <!DOCTYPE html>
    21. <html lang="en">
    22. <head>
    23.     <meta charset="UTF-8">
    24.     <title>Document</title>
    25. </head>
    26. <body>
    27.     <form action="" method="post">
    28.         <input type="text" name="name" placeholder="Name"><br>
    29.         <input type="text" name="email" placeholder="Email"> <br>
    30.         <textarea name="message" placeholder="Message"></textarea><br>
    31.         <input type="submit" value="Отправить" name="send_email"><br>
    32.     </form>
    33. </body>
    34. </html>
    Это основная задумка. Дальше под себя подстраивайте.
    Если смог помочь - с вас лайк :)
     
    Алекс8 нравится это.
  8. Arina

    Arina Новичок

    С нами с:
    21 июн 2017
    Сообщения:
    13
    Симпатии:
    0
    Спасибо за помощь! Хотелось бы ошибку найти, а код тот же оставить, поможете хоть 10 лайков с поцелуем