使用Swift邮件程序SmtpTransport进行PHP解析错误解析错误

For testing sake, I want to send an email from my Heroku server with a hardcoded message. When I call the page "sendMessage.php," I get a 500 error on Heroku. To investigate the 500 error, I bring the code down the MAMP to investigate the log errors. When I do that, I get the following syntactical error:

PHP Parse error:  syntax error, unexpected '$transport' (T_VARIABLE) in /Applications/MAMP/htdocs/sendmail.php on line 6

Here's what my code looks like. I downloaded the latest version of swift mailer from github. Any help would be greatly appreciated. Thanks!

<?php 

 require 'SwiftMailer/lib/swift_required.php'


$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
            ->setUserName('FOO@gmail.com')
            ->setPassword('BAR');


$swift = Swift_Message::newInstance($transport)


$content = "This is a test message.";



$message = Swift_Message::newInstance("This is a test email")
            ->setFrom("FOO@gmail.com")
            ->setTo('BAR@gmail.com')
            ->setBody($content,'text/html')
            ->addPart(strip_tags($content),'text/plain');



$swift->send($message);


?>
donglian4770
donglian4770 你也错过了;在$swift=Swift_Message::newInstance($transport)的末尾
4 年多之前 回复
doujionggan9570
doujionggan9570 失踪;在您的需求行的末尾
4 年多之前 回复

1个回答

You are missing semi colon ; in two lines. Here is correction.

require 'SwiftMailer/lib/swift_required.php'; // missing ; here

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
            ->setUserName('FOO@gmail.com')
            ->setPassword('BAR');
$swift = Swift_Message::newInstance($transport); // missing ; here

$content = "This is a test message.";

$message = Swift_Message::newInstance("This is a test email")
            ->setFrom("FOO@gmail.com")
            ->setTo('BAR@gmail.com')
            ->setBody($content,'text/html')
            ->addPart(strip_tags($content),'text/plain');

$swift->send($message);
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐