我目前正在运行xampp本地服务器。
但是Swiftmailer一直在遇到这个问题。
这是我正在使用的代码:
<?php
require_once 'vendor/autoload.php';
echo 'Mail sent <br>';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
->setUsername('myemail@gmail.com')
->setPassword('mypassword');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('myemail@gmail.com'))
->setTo(array('theiremail@gmail.com'))
->setBody('Hello World.');
$result = $mailer->send($message);
if (!$mailer->send($message,$failures)) {
echo "Failures:";
print_r($failures);
} else {
echo "sent";
}
?>
这是一直出现的错误消息:
致命错误:带有消息的未捕获异常'Swift_TransportException' '无法与C:\ xampp \ htdocs \ lulbasaur \ vendor \ swiftmailer \ swiftmailer \ lib \ classes \ Swift \ Transport \ StreamBuffer.php中的主机smtp.gmail.com [#0]'建立连接:268堆栈跟踪: #0 C:\ xampp \ htdocs \ lulbasaur \ vendor \ swiftmailer \ swiftmailer \ lib \ classes \ Swift \ Transport \ StreamBuffer.php(62):Swift_Transport_StreamBuffer-&gt; _establishSocketConnection()#1 C:\ xampp \ htdocs \ lulbasaur \ vendor \ swiftmailer \ swiftmailer \ lib \ classes \ Swift \ Transport \ AbstractSmtpTransport.php(113):Swift_Transport_StreamBuffer-&gt; initialize(Array)#2 C:\ xampp \ htdocs \ lulbasaur \ vendor \ swiftmailer \ swiftmailer \ lib \ classes \ Swift \ Mailer.php(79):Swift_Transport_AbstractSmtpTransport-&gt; start()#3 C:\ xampp \ htdocs \ lulbasaur \ sample_pdf.php(19):Swift_Mailer-&gt; send(Object(Swift_Message))#4 {main}在第268行的C:\ xampp \ htdocs \ lulbasaur \ vendor \ swiftmailer \ swiftmailer \ lib \ classes \ Swift \ Transport \ StreamBuffer.php中抛出
我使用composer通过使用以下命令在服务器上安装它:
composer需要swiftmailer / swiftmailer
我的设置不正确吗?