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. Wishlist Icon in Divi Blog module (loop)
  17. How to fix pagination for custom loops?
  18. Jquery Slider for profile template
  19. Counting the posts of a custom WordPress loop (WP_Query)?
  20. if ( is_home() && ! is_front_page() )
  21. Get excerpt using get_the_excerpt outside a loop
  22. Get post content from outside the loop
  23. Why should I put if(have_posts()), is while(have_posts()) not enough?
  24. Display featured products through custom loop in woocommerce on template page
  25. Split Content and Gallery
  26. How to get Author ID outside the loop
  27. How can i display the content in plaintext
  28. Redirect loop when trying to login to /wp-admin/ [duplicate]
  29. How to split a loop into multiple columns
  30. Is it necessary to reset the query after using get_posts()?
  31. Is there any difference between the_title() and echo get_the_title()?
  32. AJAX with loop filtering categories
  33. Do I need to use The Loop on pages?
  34. Remove the Homepage Query
  35. remove tags from the_content
  36. the_title() shows title of the first post instead of the page title?
  37. How to force excerpts / teasers in the loop
  38. Retrieve each widget separately from a sidebar
  39. Why am I being limited to ten posts on a custom loop?
  40. Should I use loop in the single.php file?
  41. A search for ‘0’ returns results
  42. Why do themes rely on “The Loop”?
  43. How to return loop contents
  44. Using the Loop to show all levels of subpages under a parent page? Halfway there
  45. Cleanest Way to Select Every Second Element in a Loop?
  46. Insert image or ad script after 3 posts using the loop
  47. Get date of last update outside of loop
  48. Pagination not working on home page
  49. Child Pages Loop
  50. How to place comments_template(); outside the loop?
  51. Multiple Loops Homepage?
  52. How to Change Loop to Order Posts by Views (using wp-postviews plugin)
  53. how to upload image using wp_handle_upload
  54. Avoiding using a loop to access a single post
  55. Strategy to get post meta for use outside the loop
  56. How to get the first image gallery of a product in woocommerce in a loop
  57. Get post by page name or slug
  58. save_post + insert_post = infinite loop
  59. Loop.php vs looping inside template file
  60. Custom Loop and Infinite Scroll
  61. Query Custom Meta Value with Increment
  62. Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content
  63. is_home, and is_front_page conditional problem
  64. Is `query_posts` really slower than secondary query?
  65. Are there any scenarios where the query_posts may be used?
  66. the_content and wp_link_pages
  67. Adding ‘current_post_item’ class to current post in the loop
  68. How do I get the attributes of a short code from a post?
  69. How can I custom order the results from wp_list_categories?
  70. ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
  71. WooCommerce Product Page Loop – Output All Product Thumbnails
  72. wp-admin redirecting to https, denying login
  73. Endless loop with wp_insert_post and wp_update_post
  74. Display subpages under parent page as a list within a loop
  75. Why is it necessary to call rewind_posts() when using the loop more than once? [duplicate]
  76. When to use wp_reset_postdata();
  77. Is including the loop necessary for page.php? [duplicate]
  78. the_title(); works in a page template, outside the loop. Why?
  79. wordpress loop for specific category
  80. Add 20yrs to post date, and then query
  81. Why do themes have `while( have_posts() )` in templates like single.php?
  82. When and Why is is_singular(‘my_cpt’) true while in_the_loop() is false?
  83. Three different post types on homepage
  84. What is best way passing variables to theme templates and using them different places like widgets?
  85. Apply styling only to first page sticky posts
  86. WordPress category & taxonomy loop with pagination
  87. Add Incrementing ID to each paragraph in the_content
  88. Changing behavior of the loop twice in one page
  89. How do I prevent one of two multiple loops from repeating on a second page?
  90. Insert/sticky specific post into Loop at specific location
  91. Style every four posts differently [duplicate]
  92. Return vs Echo Shortcode
  93. wp_list_categories: get latest featured_image of category
  94. Hook into the loop via a plugin, and output something after every X post?
  95. Grossly inefficient wordpress loops!
  96. Multiple posts with one loop iteration
  97. Two custom loops, pagination, offset
  98. Is it possible to sort the post based on a custom field?
  99. Identify the page being shown while in The Loop
  100. WordPress Alphabetical Glossary close div in loop
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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