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.
Anybody an idea? I am still struggling with this.
Anyone an idea?
I also have trying to set fixed value for the wp_mail and I am using a plugin “WP Mail SMTP”, which works as I can send a test email.
So even with the fixed value the wp_mail won’t send an email.
@hube2, thanks for your reply.
The saving works, so thats not the issue.
I also tried using: $_POST[‘acf’][‘field_5d49dcb49a31f’] instead of get_field(’email’, $post_id), makes no difference.
I am out of ideas at the moment.
Maybe the placement of the code is not correct?
Cheers
Never mind, it was a css style that was hiding the message.
I know this is an old thread, but I have the same issue with the latest version.
The url contains ?updated=true but the message is never shown.
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.