2014-01-21 60 views
0

當前我正在使用以下腳本。該腳本將發送一封電子郵件給email1,但並非總是如此。PHP腳本:發送到另一個帶有SMTP的電子郵件地址

當有人添加第二EMAIL2,電子郵件只到2號。

我想改變腳本發送到兩個電子郵件(1和2)當EMAIL2存在。

嘗試了很多東西,但不能正確對待。

//電子郵件

if(!$row->email2){ 
     $email = $row->email1; 
    } else{ 
     $email = $row->email2; 

//試過低於這個和很多更

if(!$row->email2){ 
     $email = $row->email1; 
    } else{ 
     $email = $row->email1; 
     $email = $row->email2; 

//推薦給

if(!is_array($email)){ 
     $mail->ClearAddresses(); 
     $mail->AddAddress($email); 
     $mail->Send(); 
    } else{ 
     foreach($email as $email){ 
      $mail->ClearAddresses(); 
      $mail->AddAddress($email); 
      $mail->Send(); 

回答

0
$emails = array(); 

if($email = $row->email1) { 
    $emails[] = $email; 
} 

if($email = $row->email2) { 
    $emails[] = $email; 
} 

foreach($email as $email){ 
    $mail->ClearAddresses(); 
    $mail->AddAddress($email); 
    $mail->Send(); 
} 
相關問題