phpzend-framework2zend-mail

Got parse error with Mail config headers in ZF2


I use Zend\Mail\Transport\Smtp to send an email. Below is my code.

use Zend\Mail\Message;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
 public function smtpConfig($message)
    {
        $transport = new SmtpTransport();
        $options   = new SmtpOptions(array(
        'name' => localhost,
        //'host' => 10.92.32.81,
        'port' => 25,
        ));

    $transport->setOptions($options);
    echo $transport->send($message);
}
public function sendMail($to,$from,$subject,$body)
    {    
        $message = new Message();
        $message->addTo($to)
                ->addFrom($from)
                ->setSubject($subject)
                ->setBody($body);
        $this->smtpConfig($message);
    }

I have configured smtp in local system and I'm able to receive email without any warnings/low priority errors. I delivered this code for project testing. Mail functionality is working fine in their system but in browser console following warning/error is displayed and I dont see this error in my local setup.

Parse error: syntax error, unexpected '[' in D:\applications\www-php\kiosquebo\vendor\zendframework\zend-mail\src\Headers.php on line 39

Any solution given is appreciated.


Solution

  • According to the line in the file you're getting the error, PHP is failing to parse this line:

    protected $headersKeys = [];
    

    The only issue that is possible here is that your PHP version is too old and does not work with the [] array definer.

    You should update your PHP version to at least 5.4.