开发者

Getting a parse error when trying to send email using Zend Mail? Why? [closed]

开发者 https://www.devze.com 2022-12-29 19:05 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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->开发者_StackOverflow社区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


Instead of catch($e){ use

catch (Exception $e) {

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


($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';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号