Support Forum
Support › MB Frontend Submission › receive notifications
Using mb frontend submission, how to set up email in shortcode to receive notifications of new articles published?
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
if ( 'my-meta-box' === $config['id'] ) {
wp_mail( '[email protected]', 'New submission', 'A new post has been just submitted.' );
wp_safe_redirect( 'thank-you' );
die;
}
}, 10, 2 );
do_action( 'rwmb_frontend_after_process', 'date_now', 75 );
Hello,
There is a parameter rwmb_frontend_field_post_id
in the URL when you edit a post. Then you can use the code below to check if it is a new post submitted (not an edited post):
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
if( empty( $_GET['rwmb_frontend_field_post_id'] ) ) {
// your code to send email goes here
}
}, 20, 2 );
01.How can I have this function for a specific form, or can I send it to different mailboxes for different forms?
02.In addition, the letter was successfully sent to "Chinese" instead of "English"!
add_filter( 'rwmb_frontend_field_value_post_id', 'my_custom_population_function', 10, 2 );
function my_custom_population_function( $value, $args ) {
if ( $args['id'] === 'date_now' ) { // Only filter for a specific form.
$value = 123;
}
return $value;
}
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
if( !empty( $_GET['rwmb_frontend_field_post_id'] ) ) {
wp_mail( '[email protected]','New submission', 'A new post has been just submitted.');
wp_safe_redirect( 'thank-you' );
die;
}
}, 20, 2 );
03.If there is an email address set on the form to fill in, how can this email also receive the email after filling in the form?
Hello,
1. You can combine your code in the second comment (https://support.metabox.io/topic/receive-notifications/?swcfpc=1#post-43569) to check the specific form by form ID and send the email.
2. I'm not sure if a third-party plugin can cause this issue but the send function works as it is. It isn't a Meta Box issue itself.
3. You can get the field email value via the $_POST variable. For example:
wp_mail( $_POST['custom_field_id'],'New submission', 'A new post has been just submitted.');