0

I have a new installation of Swift Mailer. When sending emails it fails and in the .errorlog file I have the following:

[25-Jun-2019 09:51:32 America/Detroit] PHP Parse error: syntax error, unexpected '?' in /home/qetbcdfu/public_html/swift/lib/classes/Swift/Transport/EsmtpTransport.php on line 213

Help appreciated!

require_once 'lib/swift_required.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('mail.authsmtp.com', 25))
->setUsername('hidden')
->setPassword('hidden');
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$themessage .= "<p>Hi this is an email message that is a test message from Cedine's Swift AuthSMTP programming interface.  I hope you have enjoyed receiving this message.</p><p><strong>Please delete this message.</strong></p>"; 
$message = Swift_Message::newInstance('An Invitation to Join the Global CHE Network')
      ->setFrom('jim@jimnull.com')
      ->setTo(array('jsnull@outlook.com', 'jnull1955@gmail.com'))
      ->setBody($themessage, 'text/html');  
// Send the message
$result = $mailer->send($message);  
print "<p>Sent</p>";
Perry
  • 11,172
  • 2
  • 27
  • 37
James S. Null
  • 83
  • 2
  • 7

1 Answers1

0

I think you run on php 5.6 since the error is on a php 7.x operator.

As we can see in the source code on line 213 they use ?? operator. This operator is available from php 7.x as is mentioned in the php docs

Since php 5.6 is already end of life you should look into upgrading to a newer version of php

Perry
  • 11,172
  • 2
  • 27
  • 37
  • Yes you are right I was on 5.6 and upgraded to 7.0. I now get the following error message: [25-Jun-2019 10:19:25 America/Detroit] PHP Fatal error: Uncaught Error: Call to undefined method Swift_Message::newInstance() in /home/qetbcdfu/public_html/swift/swifttest.php:43 Stack trace: #0 {main} thrown in /home/qetbcdfu/public_html/swift/swifttest.php on line 43 – James S. Null Jun 25 '19 at 14:20
  • @JamesS.Null what you can do is this: ```$message = (new \Swift_Message($subject)) ->setFrom('email@email', 'email')``` from there you can do all the things you want to do with the message – Perry Jun 25 '19 at 18:58
  • Thank you @Perry – James S. Null Jun 26 '19 at 19:11