Home › Forums › General Issues › wp_mail not working in acf/pre_save_post › Reply To: wp_mail not working in acf/pre_save_post
Ok, I know what was going wrong.
I didn’t used the correct priority.
Now using the following code:
function wpdocs_set_html_mail_content_type() {
return 'text/html';
}
add_action('acf/save_post' , 'my_save_post', 15);
function my_save_post($post_id) {
if( get_post_type($post_id) !== 'donations' ) {
return;
}
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
$name = get_field('post_title', $post_id);
$email = get_field('email', $post_id);
$body_text = get_field('email_tekst', 'option');
$to = $email;
$headers = array('From: some name <some email> <noreply@'.$_SERVER['HTTP_HOST'].'>');
$subject = 'Bedankt voor uw donatie: ' . get_field('bedrag', $post_id) . ' ' . get_field('periodiek', $post_id);
$message = $body_text;
wp_mail($to, $subject, $message, $headers );
remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
}
The priority is now 15, so runs after the save was done.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.