Solved this using AJAX. Here is my updated code: <?php add_action(‘wp_ajax_quote_email_pdf’, ‘quote_email_pdf’); function quote_email_pdf() { wp_mail( $to, $subject, $message, $headers, $attachments ); die(); } ?> <button class=”button” id=”downloadQuote”>Send email</button> <script> jQuery(document).ready(function($){ const fullName = $(‘#quoteFullName’).text(); const emailAddress = $(‘#quoteEmail a’).text(); $(‘#downloadQuote’).click(function(e){ e.preventDefault(); $.ajax({ url: sf_admin_ajax.sf_admin_ajax_url, type: ‘POST’, data: { action: ‘quote_email_pdf’, emailAddress: emailAddress, fullName: fullName … Read more