2014-09-10 87 views
0

我有一個數組$ emails。該print_r($emails)輸出如下:發送郵件給每個數組值

Array 
(
    [0] => Array 
     (
      [user_email] => 
     ) 

    [1] => Array 
     (
      [user_email] => [email protected] 
     ) 

    [2] => Array 
     (
      [user_email] => [email protected] 
     ) 
) 

現在我想發送電子郵件到的所有電子郵件地址此陣英寸我想:

foreach($emails as $contact) { 

$to  = $contact; 
$subject = 'the subject'; 
$message = 'hello'; 
mail($to, $subject, $message, $headers); 

} 

我得到的是:Warning: mail() expects parameter 1 to be string, array given

+3

'$接觸[ 'USER_EMAIL']' – AbraCadaver 2014-09-10 15:42:45

+0

你有一個數組的數組。因此該數組中的每個元素都是一個數組。錯誤信息很清楚,'mail()'不指望數組。 – David 2014-09-10 15:43:06

+0

您還應該檢查一個空的電子郵件,就像第一個電子郵件一樣。 – Barmar 2014-09-10 15:43:37

回答

1
foreach($emails as $contact) { 

$to  = $contact['user_email']; 
$subject = 'the subject'; 
$message = 'hello'; 
mail($to, $subject, $message, $headers); 

} 
+0

完美運作。謝謝 – 10now 2014-09-12 09:38:12