2017-06-21 2 views
0

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); 
+0

'var_dump ($ employee_emails);' zeigt, was? – CBroe

+0

@CBroe Ich habe bereits vor dem Posten debuggen. Es gibt ein Array von E-Mail-IDs –

+0

@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. –

Antwort

0

I wie unten gebraucht, seine funktionierte perfekt.

$employee_emails = array('[email protected]', '[email protected]'); 

wp_mail($employee_emails, 'subject', 'test message'); 

OR Versuch unten Methode, es ist nicht gut Praxis !,

foreach($group_emails as $email_address) 
{ 
    wp_mail($email_address, 'my subject', 'my message', $headers); 
} 
+0

Ich habe keine Ahnung, was in meinem Code falsch ist. Alles ist korrekt und noch keine E-Mail. Ich habe versucht Array, implode aber kein Glück. –

+0

OR try loop method (bearbeitete Antwort), – GNANA

Verwandte Themen