2010-05-05 13 views
0

嗨一些奇怪的原因,我無法使用Zend郵件:(發送電子郵件 - 我不斷收到以下錯誤:嘗試使用Zend Mail發送電子郵件時出現分析錯誤?爲什麼?

Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in /home/fltdata/domains/fltdata.com/public_html/admin/g-app/includes/mailer.php on line 77 

下面是我的代碼:

if($_POST): 

    $fields = array('to', 'cc', 'bcc', 'subject', 'body'); 
    $req_fields = array('to', 'subject', 'body'); 

    foreach($fields as $vv) 
    { 
     if(($_POST[$vv]=='')&&(in_array($vv, $req_fields))): 
      $errors[$vv] = strtoupper($vv.' is required'); 
     else: 
      $$vv = $_POST[$vv]; 
     endif; 
    } 

    if(count($errors)==0): 

     $to = explode(',', $_POST['to']); 
     $cc = explode(',', $_POST['cc']); 
     $bcc = explode(',', $_POST['bcc']); 

     //check if the emails are valid 
     foreach($to as $one_email) 
     { 
      if(!is_valid_email($one_email)): 
       $errors['to'].= $one_email.' is not a valid email<br/>'; 
      endif; 
     } 

     foreach($cc as $one_email) 
     { 
      if(!is_valid_email($one_email)): 
       $errors['cc'].= $one_email.' is not a valid email<br/>'; 
      endif; 
     } 

     foreach($bcc as $one_email) 
     { 
      if(!is_valid_email($one_email)): 
       $errors['bcc'].= $one_email.' is not a valid email<br/>'; 
      endif; 
     } 
    endif; 

    if(count($errors)==0): 
     $config = array( 'auth' => 'login', 
           'username' =>$current_dept->email, 
           'password' => $current_dept->email_psd); 

     $transport = new Zend_Mail_Transport_Smtp($current_dept->outgoing_server, $config); 
     Zend_Mail::setDefaultFrom($current_dept->email, _get_session('name')); 
     Zend_Mail::setDefaultReplyTo($current_dept->email); 

     $mail = new Zend_Mail(); 
     $mail->addTo($to); 

     if(count($cc)>0) 
      $mail->addCc($cc); 

     if(count($bcc)>0) 
      $mail->addBcc($bcc); 

     $mail->setSubject($subject); 
     $mail->setBodyText($body); 

     try{ 
     ($mail->send($transport)); 
     } catch($e){ // this is line 77 but wheres the error? 
      echo 'OUCH'; 
     } 

    endif; 

endif; 

的線,解析器的狀態只有一個catch語句 - 這裏哪來的錯誤,請幫忙

回答

1

($ MAIL->發($傳輸));看起來並不好

試試這個:

try{ 
    $mail->send($transport); // (...) removed 
} catch($e){ // this is line 77 but wheres the error? 
    echo 'OUCH'; 
} 
+0

我得到了它在某種程度上固定的,但如何封閉在括號中的語句是關注的事項? – Ali 2010-05-05 11:20:40

+0

有趣的是,PHP不會抱怨,但基本上你不會在這樣的語句中放置括號。我現在可以給你的唯一答案就是它的壞習慣。 – zaf 2010-05-05 11:30:44

相關問題