douxiong3234 2018-01-03 21:05
浏览 112
已采纳

SwiftMailer中EsmtpTransport.php中的问题

I am trying to send email from my application using SwiftMailer. I have installed the SwiftMailer package using git with the following command in my project folder:

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

This showed me that swiftmailer is cloned properly in my project folder. Now when I am trying to send email from my application, it is showing the following error:

 <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 />

When I tried to get into the EsmtpTransport.php file, I found the following code written:

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

The code I have written in my application is as below:

<?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(
        "recipient@somemail.com" => "Recipient Name"
        ));
        $message->setSubject($subject);
        $message->setBody($message);
        $message->setFrom("email@example.com", "My App Team");
        $mailer = Swift_Mailer::newInstance($transport);
        $mailer->send($message, $failedRecipients);
?>

I am unable to figure out the issue and tried searching the net and unfortunately not successful yet. Can anyone please help? Thanks in advance!

  • 写回答

1条回答 默认 最新

  • duanqiang3925 2018-01-03 21:15
    关注

    there's a typo in the code. They wanted to use ternary operator but instead : they put second ?. You doesn't use composer so you can just fix it yourself. Just change

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

    to

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

    or download v6.0.1, free from this bug, from here.


    @edit It's not a typo. It's Null coalescing operator. It has been introduced in PHP7.0 so I suppose you're using an older version of PHP. You should use PHP7+ because swiftmailer is aimed for this versions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何使用micpyhon解析Modbus RTU返回指定站号的湿度值,并确保正确?
  • ¥15 C++ 句柄后台鼠标拖动如何实现
  • ¥15 有人会SIRIUS 5.8.0这个软件吗
  • ¥30 comsol仿真等离激元
  • ¥15 静电纺丝煅烧后如何得到柔性纤维
  • ¥15 (标签-react native|关键词-镜像源)
  • ¥100 照片生成3D人脸视频
  • ¥15 伪装视频时长问题修改MP4的时长问题,
  • ¥15 JETSON NANO
  • ¥15 VS开发qt时如何在paintgl函数中用pushbutton控制切换纹理