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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog