Wp Mail Success or Failure Issue
-
Hello,
With wp mail, I’m trying to get data from a form based on the variable id address and send mail. I do this in the pop-up window that opens after pressing a button.If there is a post and the verify nonce is true, I am sending the data from this form. So far, so good.
However, I cannot show the user whether the mail was successful or not. According to this document, wp mail returns true or false. I tried to proceed from here. However, the strange thing is that even when I don’t send mail, wp_mail returns false. That is, it shows false even if the submit button is not pressed yet. However, if the mail is successful, there is no problem for this. I see that it was successful after the mail was sent and the page loaded.Also, to reiterate, I don’t use Ajax. After clicking the Submit button, the page reloads.
My Code is:
<?php //... if (!empty($_POST) && wp_verify_nonce($_POST['mail_control'], 'mail_control')) { //... if(!get_post_meta($order_id, 'reject_email', true)){ update_post_meta($order_id, 'reject_email', true); $to = $recipient_mails; $result_for_reject = ''; $subject = 'Rejected'; $body = $message; $headers = array('Content-Type: text/html; charset=UTF-8','From:MyWebSite <[email protected]>'); $result_for_reject = wp_mail($to, $subject, $body, $headers); } } //... //Pop-up window finished <?php //Check email is sent or not sent if($result_for_rma_reject){ echo '<div class="woocommerce-message " role="alert">Successful.</div>'; } if($result_for_rma_reject==false) { echo '<div class="woocommerce-error " role="alert">Unsuccessful.</div>'; } ?>
- The topic ‘Wp Mail Success or Failure Issue’ is closed to new replies.