最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp mail - Send automatic emails to multiple user roles when a custom field is updated in a custom post type

programmeradmin3浏览0评论

I'm trying to incorporate a 'Register interest' button into a website which when signing up will assign register the user to a user role and then when a custom field is updated in the property (CPT) it will automatically send out an email to the users who are assigned to a role letting them know a property is now available.

I have many properties in the custom post type which have a relationship to another custom post type 'court' so I've setup different user roles. If a user wants to be emailed about more than one courts properties then they will be assigned to multiple roles.

I thought by using the plugin, 'Better notifications for WordPress' with some of its premium add-ons would do the trick but this doesn't let me set a conditional rule on a custom field and only works if any property status has been published.

I've also tried setting up Mailchimp and collecting different emails on the site which would go into separate lists of the courts but I can't find anything which then allows me to setup a automatic email to go out these lists.

I did read about doing this manually through the wp_mail function following a tutorial on Smashing magazine, / but reading the comments it talks the risks of being blacklisted.

Does anyone know of any solutions / plugins which could help me build this in?

I'm trying to incorporate a 'Register interest' button into a website which when signing up will assign register the user to a user role and then when a custom field is updated in the property (CPT) it will automatically send out an email to the users who are assigned to a role letting them know a property is now available.

I have many properties in the custom post type which have a relationship to another custom post type 'court' so I've setup different user roles. If a user wants to be emailed about more than one courts properties then they will be assigned to multiple roles.

I thought by using the plugin, 'Better notifications for WordPress' with some of its premium add-ons would do the trick but this doesn't let me set a conditional rule on a custom field and only works if any property status has been published.

I've also tried setting up Mailchimp and collecting different emails on the site which would go into separate lists of the courts but I can't find anything which then allows me to setup a automatic email to go out these lists.

I did read about doing this manually through the wp_mail function following a tutorial on Smashing magazine, https://www.smashingmagazine/2015/05/building-wordpress-notification-system/ but reading the comments it talks the risks of being blacklisted.

Does anyone know of any solutions / plugins which could help me build this in?

Share Improve this question edited Dec 16, 2019 at 3:31 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Apr 5, 2017 at 8:14 ShaunShaun 1541 silver badge9 bronze badges 1
  • 1 This type of emails are called transactional emails. If you will sent a lot of emails it is better to use a service. As you mentioned there is the risk of being blacklist. Mailchimp offers Mandrill for this type of emails. Also Mailgun is a good choice. Although you have to implement what you described. – Laxmana Commented Apr 5, 2017 at 8:25
Add a comment  | 

1 Answer 1

Reset to default 1

This code will allow you to call a custom function when your meta key is updated.

add_action('updated_postmeta','my_meta_update', 10, 4);

function my_meta_update( $meta_id, $object_id, $meta_key, $meta_value ) {

    if($meta_key === 'my_meta_key') {
        // trigger email(s)
        // wp_mail( $to, $subject, $message, $headers, $attachments );
    }
}

Like Shaun mentioned, you should always use an external email solution else your ip / domain will get blacklisted. You may even have email sending restrictions from your hosting provider.

发布评论

评论列表(0)

  1. 暂无评论