Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Sending mail not working correctly

You should concatenate the messages together and then send the email outside of the loop once you’ve built up the entire message string you want to send.
Try something like this:

if ( $all_reservations_on_day_query->have_posts() ) :
         //the loop
$message_mail = ""; 
while ( $all_reservations_on_day_query->have_posts() ) : $all_reservations_on_day_query->the_post();

            //Get all values for sending mail to owner based on date.
            $klant_naam_mail = get_post_meta($post->ID, 'klant_naam', true);
            $email_mail = get_post_meta($post->ID, 'email', true);
            $telnr_mail = get_post_meta($post->ID, 'telefoonnummer', true);
            $datum_mail = get_post_meta($post->ID, 'datum', true);
            $aantal_personen_mail = get_post_meta($post->ID, 'aantal_personen', true);
            $opmerking_mail = get_post_meta($post->ID, 'opmerking', true);

            //the message for the mail
            //concatenate the messages together
            $message_mail .="Naam: $klant_naam_mail\nEmail: $email_mail\nTelefoonnummer: $telnr_mail\nDatum: $datum_mail\nAantal personen: $aantal_personen_mail\nOpmerking: $opmerking_mail";


         endwhile;

echo $message_mail . '<br>';

Related Posts:

  1. How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
  2. Get ID of a page containing secondary loop in content
  3. How to add “time” data this?
  4. Next and Previous loop
  5. How to hook into container
  6. Output meta into arrays
  7. value of metadata is null wrong use of if statement
  8. using update_user_meta to rank users
  9. get_post_meta printing empty fields, but it shouldn’t be
  10. Check value of post meta within IF statement
  11. Best way to check if a post with specific meta exists
  12. WP update_post_meta link loop
  13. Humanmade | Custom meta box class: How to display a repeatable meta box group?
  14. Display articles related to a custom field on a page
  15. wp_mail sending only once inside foreach loop
  16. How can i display the content in plaintext
  17. How to force excerpts / teasers in the loop
  18. Why am I being limited to ten posts on a custom loop?
  19. Loop.php vs looping inside template file
  20. Insert/sticky specific post into Loop at specific location
  21. Why am I getting an infinite loop with have_posts?
  22. have_posts() return false but count says “3”
  23. Ajax loop in sidebar to load post titles/categories
  24. Displaying custom posts only if custom meta box’s date is not expired
  25. wordpress post loop in javascript
  26. How to iterate through database until it find a match
  27. Create a random unique 6 digit number as custom field for custom post type
  28. Loop through pages with specific template
  29. Loop starts from the beginning with second while loop on author.php
  30. wordpress change the loop order by dynamic value
  31. Single page site (WordPress) including posts
  32. Meta Query with spaces in value?
  33. A loop with all articles with certain text strings in tags
  34. Prevent Headers from being sent
  35. How do I get row padding in a post feed?
  36. Display the_content on click jquery
  37. How can I create a legend (Key) like the one in the footer on WordPress StackExchange
  38. It is possible to encounter horrible bugs if I place a main loop that uses `query_posts` right above the main bbPress loop?
  39. Missing image in gallery shortcode in custom feed
  40. Styling text and images in the_content()
  41. How do I use AJAX Query in my posts loop?
  42. How to show “teaser” posts on blog / archive pages, otherwise full posts
  43. Output loop leveraged shortcode twice on one page
  44. Alter query using pre_get_posts() if meta_key is present
  45. Next Posts Prev Posts for Standard post format only
  46. Genesis multiple category custom loop 404s after first page
  47. Modified loop-single-forum.php to work inside of a sidebar Widget, not working on some site pages
  48. Basic multiple loops only displaying first loop
  49. Both a page loop and posts loop on the same page
  50. WordPress Blog has an infinite redirect loop
  51. Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
  52. How to create bootstrap grid loop?
  53. Is it possible to reverse the order of a list of posts pulled from a loop?
  54. First article : single column; Other articles : 2 columns
  55. How can I access specific posts brought back by query_posts?
  56. Put multiple custom loops on same page
  57. Contact information footer
  58. custom post on homepage
  59. Multisite foreach loop returning only one result
  60. Loop is crazy – one row displays wrong count of posts [closed]
  61. loop inside the foreach
  62. Is there a way getting post fields using `transition_post_status`
  63. How to display 3 post per slide
  64. How to put a block of code between [shortcode][/shortcode] in do_shortcode()?
  65. current-user_can not working in loop
  66. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  67. Show terms in archive page
  68. How can I access a post’s feature image outside the loop?
  69. Multiple loops for plugin
  70. Sort posts according to a numeric value entered with ACF
  71. wp_get_attachment_url not fetching URL?
  72. Undefined index: page in loop load ajax content
  73. Only Show Excerpt After First 3 Posts
  74. How to get all multi-select user meta values and add them to an array?
  75. How to insert content before pagination in loop?
  76. How to resolve a reload loop issue in the frontend when logged in to WordPress multi-site backend admin area
  77. Excerpt isn’t working or am I missing something?
  78. Can I temporarily disable global $post?
  79. Shortcode for pulling specific Post Title outside loop when ID is passed in
  80. Deeply Nested Menu Loop with Twig using Timber [closed]
  81. WordPress redundant posts based on meta field
  82. Efficient way of querying for a “fallback” post?
  83. Get featured image outside the loop using foreach
  84. Infinite Loop after Genesis Theme Upgrade
  85. pre_get_posts main_query not displaying after applying tax_query filters
  86. WordPress loop only displays 5 articles max?
  87. setup_postdata in “loop-handling” php file called via $.ajax
  88. Secondary loop cuts off at 10 posts?
  89. loop through custom post types with meta data
  90. get all page templates
  91. Paged homepage – requirements?
  92. Least Number of Loops to Create Custom Homepage?
  93. strange parse error when including a loop template within another template
  94. Previous Posts Link and Next Posts Link Show All The Same Articles?
  95. Posts Loops To Display Specific Posts Inside Page Template?
  96. Use callback function in AJAX pure javascript [closed]
  97. Undefined variable: woocommerce_loop [closed]
  98. title not being printed within html tag [closed]
  99. Prevent duplicating specific column from database table
  100. Hook in the loop after the first post
Categories loop Tags loop, post-meta, wp-mail
page template with custom post type loop case page duplication
How do i add slugs to a URL, but still redirecting to the same page

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress