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

发布于 2024-08-31 01:05:14 字数 2408 浏览 7 评论 0原文

大家好,由于一些奇怪的原因,我无法使用 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 语句 - 这里的错误在哪里,请帮忙

Hi guys for some weird reason I'm unable to send email using zend mail :( - I keep getting the following error:

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

Below is my code:

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;

The line which the parser states only has a catch statement - wheres the error here please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话难免假 2024-09-07 01:05:14

而不是 catch($e){

catch (Exception $e) {

请参阅 http://docs.php, .net/语言.例外

Instead of catch($e){ use

catch (Exception $e) {

see http://docs.php.net/language.exceptions

凡间太子 2024-09-07 01:05:14

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

试试这个:

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

($mail->send($transport)); doesn't look to good.

Try this:

try{
    $mail->send($transport); // (...) removed
} catch($e){ // this is line 77 but wheres the error?
    echo 'OUCH';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文