尝试使用Zend Mail发送电子邮件时出现解析错误?为什么?

时间:2010-05-05 06:54:16

标签: php zend-framework error-handling zend-mail

嗨,大家好奇怪我无法使用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语句 - 这里的错误请帮助

2 个答案:

答案 0 :(得分:3)

而不是 catch($ e){使用

catch (Exception $e) {

请参阅http://docs.php.net/language.exceptions

答案 1 :(得分:1)

($ mail-&gt; send($ transport)); 看起来不太好。

试试这个:

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