2012-03-18 2 views
2

SwiftMailer가 array()으로 이메일 주소를 가져 오려고합니다. 원래 예제가 있는데 그 안에 넣고 싶은 것을 알고 있지만 나무에서 숲을 볼 수는 없습니다 ... 적절한 눈 거기에 하나라도하십시오PHP 배열 및 mysql 구문 오류

여기
// Send the message 
$result = $mailer->send($message); 

// Send the message 
$failedRecipients = array(); 
$numSent = 0; 

내가 어려움을 겪고 있어요된다 :이 echo가 작동

foreach($groups as $value) 
    { 
      echo "<h3>".$value."</h3>"; //this is working 

    // get the email groups 
    $sql="SELECT * FROM emails WHERE sendesstat=1 AND deleted=0 AND classhoz=\"".$value."\""; 
    $query=mysql_query($sql); 

    // fetch the emails from the group 
    while($data=mysql_fetch_array($query)) 
       { 
        $emil="'".$data["email"]."' => '".$data["firstname"]." ".$data["surname"]."'"; 
        echo $emil; 

을하지만 난 $to[] 배열에 넣을 수 없습니다 ... (죄송합니다) 다음과 같이 표시됩니다.

$to = array('[email protected]', '[email protected]' => 'A name'); 

문제는 given name => 'A name'입니다. 아프다. 구문을 찾을 수 없습니다.

    $to[ ]= $emil;    
       } 
    } 

foreach ($to as $address => $name) 
{ 
    if (is_int($address)) { 
    $message->setTo($name); 
    } else { 
    $message->setTo(array($address => $name)); 
} 

$numSent += $mailer->send($message, $failedRecipients); 
} 

printf("Sent %d messages\n", $numSent); 

제발 제발 다른 모든 것들은 현재 작동하고 있습니다.이 비트가 없습니다. 감사합니다

답변

1

$to 배열을 잘못 정의했습니다.

사용이 당신이 foreach 루프를 사용하는 경우가 아니라, $ 주소와 $ 이름으로 당신이하고있는 단지 방법을 차별화한다,

$to[$data["email"]] = $data["firstname"]." ".$data["surname"]; 
//^Index   ^Value 

나중에 배열에 항목을 추가 할 수 있습니다.

foreach ($to as $address => $name) { 
    echo $address; 
    echo $name; 
} 
+0

덕분에 아주 많이 나는 내 코드에 넣어 갈거야 :)))) 덕분에 많은 다시 –

+0

@AndrasSebestyen, 내가 당신을 위해 일한 기뻐요. – Starx