发布时event
CPT,我想向自定义元框中设置的每个参与者发送电子邮件。
当我经过时array
作为电子邮件地址,它不发送电子邮件
wp_mail( $employee_emails, $subject, $message );
但如果我使用字符串,它就会发送电子邮件。我不明白代码有什么问题,或者
wp_mail
wp_mail( \'[email protected]\', $subject, $message );
我的代码
function ac_send_event_notification( $ID, $post ) {
if ( wp_is_post_revision( $ID ) ) {
return;
}
// employees details
$employees = rwmb_meta( \'ac_event_employees\', [], $ID );
$positions = rwmb_meta( \'ac_event_positions\', [], $ID );
$operations = rwmb_meta( \'ac_event_operations\', [], $ID );
// event details
$operation_user_ids = [];
if ( ! empty( $operations ) ) {
foreach ( $operations as $operation ) {
$operation_user_ids[] = ac_get_event_participants_ids_by_operation( $operation );
}
}
$position_user_ids = [];
if ( ! empty( $positions ) ) {
foreach ( $positions as $position ) {
$position_user_ids[] = ac_get_event_participants_ids_by_position( $position );
}
}
$operation_ids = array_reduce( $operation_user_ids, \'array_merge\', [] );
$position_ids = array_reduce( $position_user_ids, \'array_merge\', [] );
sort( $employees );
sort( $operation_ids );
sort( $position_ids );
$employee_ids_to_notify = array_unique( array_merge( $employees, $operation_ids, $position_ids ) );
sort( $employee_ids_to_notify );
// get employees email ids
if ( ! empty( $employee_ids_to_notify ) ) {
foreach ( $employee_ids_to_notify as $employee ) {
$employee_emails[] = get_the_author_meta( \'email\', $employee );
}
}
// Sending email to the participants
$author = $post->post_author; /* Post author ID. */
$name = get_the_author_meta( \'display_name\', $author );
$subject = sprintf( \'New Event Created by %s\', $name );
$message = "Hello,\\n\\n";
$message .= "There is a new event created by {$name}.\\n\\n";
$message .= "Check out all details with the following link.\\n\\n";
$message .= get_the_permalink( $ID );
wp_mail( $employee_emails, $subject, $message );
}
add_action( \'publish_event\', \'ac_send_event_notification\', 10, 2 );