Advertisement
Guest User

Reservation not sending email

a guest
Feb 1st, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.43 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Page: Reservation
  4. */
  5. ?>
  6. <?php
  7.  
  8. if(isset($_POST['submitted'])) {
  9.  
  10. if(trim($_POST['reservation_datepicker']) === '') {
  11. $datepicker_error = __('Please select a date!', 'gp');
  12. $has_error = true;
  13. } else {
  14. $date_field = trim($_POST['reservation_datepicker']);
  15. }
  16.  
  17. if(trim($_POST['reservation_time']) === '') {
  18. $time_error = __('Please fill the time!', 'gp');
  19. $has_error = true;
  20. } else {
  21. $time_field = trim($_POST['reservation_time']);
  22. }
  23.  
  24. if(trim($_POST['reservation_persons']) === '') {
  25. $persons_error = __('Please fill the number of persons!', 'gp');
  26. $has_error = true;
  27. } else {
  28. $persons_field = trim($_POST['reservation_persons']);
  29. }
  30.  
  31. if(trim($_POST['reservation_name']) === '') {
  32. $name_error = __('Please fill your name!', 'gp');
  33. $has_error = true;
  34. } else {
  35. $name_field = trim($_POST['reservation_name']);
  36. }
  37.  
  38. if(trim($_POST['reservation_phone']) === '') {
  39. $phone_error = __('Please fill your phone number!', 'gp');
  40. $has_error = true;
  41. } else {
  42. $phone_field = trim($_POST['reservation_phone']);
  43. }
  44.  
  45. if(trim($_POST['reservation_email']) === '') {
  46. $email_error = __('Please fill your email address!', 'gp');
  47. $has_error = true;
  48. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['reservation_email']))) {
  49. $email_error = __('Please fill your valid email address!', 'gp');
  50. $has_error = true;
  51. } else {
  52. $email_field = trim($_POST['reservation_email']);
  53. }
  54.  
  55. if(function_exists('stripslashes')) {
  56. $message_field = stripslashes(trim($_POST['reservation_message']));
  57. } else {
  58. $message_field = trim($_POST['reservation_message']);
  59. }
  60.  
  61. if(!isset($has_error)) {
  62.  
  63. $date_title = __('Date and time:', 'gp');
  64. $persons_title = __('Number of persons:', 'gp');
  65. $name_title = __('Name:', 'gp');
  66. $phone_title = __('Phone:', 'gp');
  67. $email_title = __('Email:', 'gp');
  68. $message_title = __('Message:', 'gp');
  69.  
  70. $to = get_option('gp_form_reservations_email');
  71. if (!isset($to) || ($to == '') ){
  72. $to = get_option('admin_email');
  73. }
  74. $subject = get_option('gp_form_reservations_subject');
  75. $body = "
  76.  
  77. <html>
  78. <body style='font-family:Arial, Verdana, Tahoma, sans-serif;margin:0;padding:0;font-size:12px;color:#50505a;'>
  79.  
  80. <table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#f5f5fa'>
  81.  
  82. <tr>
  83. <td style='background:#f5f5fa;' align='center'>
  84.  
  85. <table width='600' border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' style='padding:15px 30px 30px 30px; margin:30px 0;'>
  86.  
  87. <tr>
  88. <th colspan='2' style='text-align: left;'><h1 style='font-size:22px;padding-bottom:10px;'>$subject</h1></th>
  89. </tr>
  90.  
  91. <tr>
  92. <th style='text-align:left;width:150px;padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  93. $date_title
  94. </th>
  95. <td style='padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  96. $date_field, $time_field
  97. </td>
  98. </tr>
  99.  
  100. <tr>
  101. <th style='text-align:left;width:150px;padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  102. $persons_title
  103. </th>
  104. <td style='padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  105. $persons_field
  106. </td>
  107. </tr>
  108.  
  109. <tr>
  110. <th style='text-align:left;width:150px;padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  111. $name_title
  112. </th>
  113. <td style='padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  114. $name_field
  115. </td>
  116. </tr>
  117.  
  118. <tr>
  119. <th style='text-align:left;width:150px;padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  120. $phone_title
  121. </th>
  122. <td style='padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  123. $phone_field
  124. </td>
  125. </tr>
  126.  
  127. <tr>
  128. <th style='text-align:left;width:150px;padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  129. $email_title
  130. </th>
  131. <td style='padding:7px 0;border-bottom:1px solid #f5f5fa;'>
  132. $email_field
  133. </td>
  134. </tr>
  135.  
  136. <tr>
  137. <th valign='top' style='text-align:left;width:150px;padding: 7px 0;'>
  138. $message_title
  139. </th>
  140. <td style='padding:7px 0;'>
  141. $message_field
  142. </td>
  143. </tr>
  144.  
  145. </table>
  146.  
  147. </td>
  148. </tr>
  149.  
  150. </table>
  151.  
  152. </body>
  153. </html>
  154.  
  155. ";
  156.  
  157. $headers = array('From: ' . $name_field . ' <' . $email_field . '>', 'Content-Type: text/html', 'Reply-To:' . $email_field);
  158. $h = implode("\r\n",$headers) . "\r\n";
  159.  
  160. wp_mail($to, $subject, $body, $h);
  161. $has_sent = true;
  162. }
  163. }
  164.  
  165. ?>
  166. <?php get_header(); ?>
  167.  
  168. <header class="page-header">
  169. <h1><?php the_title(); ?></h1>
  170. </header><!-- page-header -->
  171.  
  172. <div class="content shadow-top left">
  173. <div class="content-container">
  174.  
  175. <div class="page-full left">
  176. <div class="page-full-container">
  177.  
  178. <?php
  179. if (have_posts()) {
  180. while (have_posts()) {
  181. the_post();
  182. ?>
  183. <?php if (!empty($post->post_content)) { ?>
  184. <div class="content-page left">
  185. <div class="content-page-container">
  186. <?php the_content(); ?>
  187. </div><!-- content-page-container -->
  188. </div><!-- content-page -->
  189. <?php } ?>
  190.  
  191. <div class="form-reservation">
  192.  
  193. <form action="<?php the_permalink(); ?>" id="form-reservation" class="form" method="post">
  194.  
  195. <fieldset>
  196.  
  197. <div class="form-block first left">
  198.  
  199. <header class="form-header">
  200. <h2><?php _e('Reservation information', 'gp'); ?></h2>
  201. </header><!-- form-header -->
  202.  
  203. <div class="input-box left">
  204. <label for="reservation_datepicker" ><?php _e('Date', 'gp'); ?>:</label> <span class="required-star">*</span><br />
  205. <input name="reservation_datepicker" id="reservation_datepicker" title="<?php _e('Please select a date!', 'gp'); ?>" class="required<?php if($datepicker_error != '') { ?> error<?php } ?>" type="text" value="<?php if(isset($_POST['reservation_datepicker'])) echo $_POST['reservation_datepicker'];?>" />
  206. <?php if($datepicker_error != '') { ?>
  207. <label for="reservation_datepicker" class="error"><?php echo $datepicker_error; ?></label>
  208. <?php } ?>
  209. </div><!-- input-box -->
  210.  
  211. <div class="input-box left">
  212. <label for="reservation_time"><?php _e('Time', 'gp'); ?>:</label> <span class="required-star">*</span><br />
  213. <input name="reservation_time" id="reservation_time" title="<?php _e('Please fill the time!', 'gp'); ?>" class="required<?php if($time_error != '') { ?> error<?php } ?>" type="text" value="<?php if(isset($_POST['reservation_time'])) echo $_POST['reservation_time'];?>" />
  214. <?php if($time_error != '') { ?>
  215. <label for="reservation_time" class="error"><?php echo $time_error; ?></label>
  216. <?php } ?>
  217. </div><!-- input-box -->
  218.  
  219. <div class="input-box left last">
  220. <label for="reservation_persons"><?php _e('Number of persons', 'gp'); ?>:</label> <span class="required-star">*</span><br />
  221. <input name="reservation_persons" id="reservation_persons" title="<?php _e('Please fill the number of persons!', 'gp'); ?>" class="required number<?php if($persons_error != '') { ?> error<?php } ?>" type="text" value="<?php if(isset($_POST['reservation_persons'])) echo $_POST['reservation_persons'];?>" />
  222. <?php if($persons_error != '') { ?>
  223. <label for="reservation_persons" class="error"><?php echo $persons_error; ?></label>
  224. <?php } ?>
  225. </div><!-- input-box -->
  226.  
  227. <br class="clear" />
  228. </div><!-- form-block -->
  229.  
  230. <div class="form-block">
  231.  
  232. <header class="form-header">
  233. <h2><?php _e('Personal information', 'gp'); ?></h2>
  234. </header>
  235.  
  236. <div class="input-box left">
  237. <label for="reservation_name"><?php _e('Name', 'gp'); ?>:</label> <span class="required-star">*</span><br />
  238. <input name="reservation_name" id="reservation_name" title="<?php _e('Please fill your name!', 'gp'); ?>" class="required<?php if($name_error != '') { ?> error<?php } ?>" type="text" value="<?php if(isset($_POST['reservation_name'])) echo $_POST['reservation_name'];?>" />
  239. <?php if($name_error != '') { ?>
  240. <label for="reservation_name" class="error"><?php echo $name_error; ?></label>
  241. <?php } ?>
  242. </div><!-- input-box -->
  243.  
  244. <div class="input-box left">
  245. <label for="reservation_phone"><?php _e('Phone', 'gp'); ?>:</label> <span class="required-star">*</span><br />
  246. <input name="reservation_phone" id="reservation_phone" title="<?php _e('Please fill your phone number!', 'gp'); ?>" class="required number<?php if($phone_error != '') { ?> error<?php } ?>" type="text" value="<?php if(isset($_POST['reservation_phone'])) echo $_POST['reservation_phone'];?>" />
  247. <?php if($phone_error != '') { ?>
  248. <label for="reservation_phone" class="error"><?php echo $phone_error; ?></label>
  249. <?php } ?>
  250. </div><!-- input-box -->
  251.  
  252. <div class="input-box last left">
  253. <label for="reservation_email"><?php _e('Email', 'gp'); ?>:</label> <span class="required-star">*</span><br />
  254. <input name="reservation_email" id="reservation_email" title="<?php _e('Please fill your email address!', 'gp'); ?>" class="required email<?php if($email_error != '') { ?> error<?php } ?>" type="text" value="<?php if(isset($_POST['reservation_email'])) echo $_POST['reservation_email'];?>" />
  255. <?php if($email_error != '') { ?>
  256. <label for="reservation_email" class="error"><?php echo $email_error; ?></label>
  257. <?php } ?>
  258. </div><!-- input-box -->
  259.  
  260. <div class="input-box-wide left">
  261. <label for="reservation_message"><?php _e('Message', 'gp'); ?>:</label><br />
  262. <textarea name="reservation_message" id="reservation_message" cols="110" rows="5" title="<?php _e('Please fill the message!', 'gp'); ?>"><?php if(isset($_POST['reservation_message'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['reservation_message']); } else { echo $_POST['reservation_message']; } } ?></textarea>
  263. </div><!-- input-box-wide -->
  264.  
  265. <br class="clear" />
  266. </div><!-- form-block -->
  267.  
  268. <div class="buttons left">
  269. <button type="submit" name="button-submit" class="button-standard left" title="<?php _e('Make a reservation', 'gp'); ?>"><?php _e('Make a reservation', 'gp'); ?></button>
  270. <input type="hidden" name="submitted" id="submitted" value="true" />
  271. <div class="required-star-info">* <?php _e('Required fields', 'gp'); ?></div>
  272. <div class="loading no-display"><img src="<?php echo get_template_directory_uri(); ?>/images/loading.gif" alt="" /><span><?php _e('Sending email ...', 'gp'); ?></span></div>
  273. <br class="clear" />
  274. </div><!-- buttons -->
  275.  
  276. <div class="validation-success no-display">
  277. <h4><?php _e('Thank you. Email has been sent. Our staff will confirm you the booking by email or SMS.', 'gp'); ?></h4>
  278. </div><!-- validation-success -->
  279.  
  280. <?php if(isset($has_sent) && $has_sent == true) { ?>
  281. <div class="validation-success">
  282. <h4><?php _e('Thank you. Email has been sent. Our staff will confirm you the booking by email or SMS.', 'gp'); ?></h4>
  283. </div><!-- validation-success -->
  284. <?php } ?>
  285.  
  286. </fieldset>
  287.  
  288. <br class="clear" />
  289. </form>
  290.  
  291. </div><!-- form-reservation -->
  292.  
  293. <?php
  294. } //while
  295. } //if
  296. wp_reset_query();
  297. ?>
  298.  
  299. <br class="clear" />
  300. </div><!-- page-full-container -->
  301. </div><!-- page-full -->
  302.  
  303. <br class="clear" />
  304. </div><!-- content-container -->
  305. </div><!-- content -->
  306.  
  307. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement