Auf veröffentlichen event
CPT, möchte ich E-Mails an jeden Teilnehmer in den benutzerdefinierten Meta-Boxen gesetzt.WordPress wp_mail keine E-Mail senden, wenn pass Array Variable
Wenn ich pass array
als E-Mail-Adressen es sendet keine E-Mail
wp_mail($employee_emails, $subject, $message);
aber wenn ich Zeichenfolge verwenden, als eine E-Mail zu senden. Ich verstehe nicht, was mit dem Code falsch ist oder wp_mail
wp_mail('[email protected]', $subject, $message);
My-Code
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);
'var_dump ($ employee_emails);' zeigt, was? – CBroe
@CBroe Ich habe bereits vor dem Posten debuggen. Es gibt ein Array von E-Mail-IDs –
@CBroe Zusätzlich habe ich gerade die Funktion 'ac_send_event_notification()' in der 'single.php' getestet und es sendet eine E-Mail, wenn die Seite geladen wird. Also ich glaube, dass etwas mit dem Haken oder mit meinem Code für 'HOOK' falsch sein muss. –