ZF2 中的邮件配置 headers 出现解析错误
Got parse error with Mail config headers in ZF2
我使用Zend\Mail\Transport\Smtp发送电子邮件。下面是我的代码。
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);
}
我已经在本地系统中配置了 smtp,并且我能够在没有任何 warnings/low 优先级错误的情况下接收电子邮件。我交付了此代码以进行项目测试。邮件功能在他们的系统中运行良好,但在浏览器控制台中显示 warning/error 之后,我在本地设置中没有看到此错误。
Parse error: syntax error, unexpected '[' in D:\applications\www-php\kiosquebo\vendor\zendframework\zend-mail\src\Headers.php on line 39
感谢您提供的任何解决方案。
根据第 in the file 行,您遇到错误,PHP 无法解析此行:
protected $headersKeys = [];
这里唯一可能的问题是您的 PHP 版本太旧,无法与 []
数组定义器一起使用。
您应该将 PHP 版本至少更新到 5.4。
我使用Zend\Mail\Transport\Smtp发送电子邮件。下面是我的代码。
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);
}
我已经在本地系统中配置了 smtp,并且我能够在没有任何 warnings/low 优先级错误的情况下接收电子邮件。我交付了此代码以进行项目测试。邮件功能在他们的系统中运行良好,但在浏览器控制台中显示 warning/error 之后,我在本地设置中没有看到此错误。
Parse error: syntax error, unexpected '[' in D:\applications\www-php\kiosquebo\vendor\zendframework\zend-mail\src\Headers.php on line 39
感谢您提供的任何解决方案。
根据第 in the file 行,您遇到错误,PHP 无法解析此行:
protected $headersKeys = [];
这里唯一可能的问题是您的 PHP 版本太旧,无法与 []
数组定义器一起使用。
您应该将 PHP 版本至少更新到 5.4。