Home › Forums › General Issues › wp_mail not working in acf/pre_save_post › Reply To: wp_mail not working in acf/pre_save_post
Is there anything else in your page code?
Actually I have the following code in page-contact.php:
<?php acf_form(array(
'id' => '138',
'post_id' => 'new_post',
'updated_message' => 'Success!',
'new_post' => array(
'post_type' => 'contact',
'post_status' => 'draft',
'post_title' => $userfirst . ' ' . $userlast .' <'.$useremail.'>'
),
'return' => home_url() . '/thank-you',
'submit_value' => 'Send'
)); ?>
In my functions.php I pasted your code, just changed to static text to test if it’s working, but without success. My host doesn’t allow mail() but I am using SMTP and it’s sending fine.
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) !== 'contact' ) {
return;
}
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
$name = get_field('post_title', $post_id);
// $body_text = get_field('email_tekst', 'option');
$to = '[email protected]';
$headers = array('From: some name <some email> <noreply@'.$_SERVER['HTTP_HOST'].'>');
$subject = 'Test!';
$message = 'Test!';
wp_mail($to, $subject, $message, $headers );
remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
}
domain.com -> client domain
If anynone could help it would be great! Stuck in it a few days. Thanks
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.