SwiftMailer中EsmtpTransport.php中的问题

问题描述 投票:0回答:1

我正在尝试使用SwiftMailer从我的应用程序发送电子邮件。我在项目文件夹中使用git和以下命令安装了SwiftMailer包:

git clone https://github.com/swiftmailer/swiftmailer.git

这告诉我swiftmailer在我的项目文件夹中正确克隆。现在,当我尝试从我的应用程序发送电子邮件时,它显示以下错误:

 <b>Parse error</b>:  syntax error, unexpected '?' in <b>C:\xampp\htdocs\myAppPath\swiftmailer\lib\classes\Swift\Transport\EsmtpTransport.php</b> on line <b>211</b><br />

当我尝试进入EsmtpTransport.php文件时,我发现以下代码:

 /**
 * Returns the IP used to connect to the destination.
 *
 * @return string
 */
public function getSourceIp()
{
    return $this->params['sourceIp'] ?? null;  //*line number 211*
}

我在我的应用程序中编写的代码如下:

<?php
    $subject = 'SwiftMailer Test!';
    $message = 'Hi! This is a test email from SwiftMailer';
    $usernameEmail = "username";
    $passwordEmail = "password";
    try{
        $transport = (new Swift_SmtpTransport('smtp.example.com', 25))
                        ->setUsername($usernameEmail)
                        ->setPassword($passwordEmail)
                    ;
        $message = Swift_Message::newInstance();
        $message->setTo(array(
        "[email protected]" => "Recipient Name"
        ));
        $message->setSubject($subject);
        $message->setBody($message);
        $message->setFrom("[email protected]", "My App Team");
        $mailer = Swift_Mailer::newInstance($transport);
        $mailer->send($message, $failedRecipients);
?>

我无法弄清楚这个问题,并尝试搜索网络,但遗憾的是还没有成功。有人可以帮忙吗?提前致谢!

php git swiftmailer
1个回答
1
投票

代码中有拼写错误。他们想使用三元运算符,而是:他们放第二个?。你没有使用作曲家,所以你可以自己修复它。只是改变

return $this->params['sourceIp'] ?? null;  //*line number 211*

return $this->params['sourceIp'] ?: null;  //*line number 211*

或者从v6.0.1下载免于这个bug的here


@edit这不是一个错字。这是Null coalescing operator。它已经在PHP7.0中引入,所以我想你使用的是旧版本的PHP。您应该使用PHP7 +,因为swiftmailer针对此版本。

© www.soinside.com 2019 - 2024. All rights reserved.