Swift 邮件程序不工作并且没有给出错误消息
Swift Mailer does not work and gives no error messages
我尝试通过 Swift-Mailer 发送电子邮件。根据文档,它应该像这样工作,但我既没有收到邮件也没有收到错误消息。
这里是 PHP Swift 文件的代码:
<?php
require_once '/composer/vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
->setUsername('*******@gmail.com')
->setPassword('password')
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['john@doe.com' => 'John Doe'])
->setTo(['infinity.community.work@gmail.com', 'other@domain.org' => 'A name'])
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
?>
这里是 composer.json:
{
"require": {
"swiftmailer/swiftmailer": "^6.0"
}
}
再次检查此语法并确保电子邮件或密码拼写正确:
$trp = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('*********@gmail.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($trp);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(['john@doe.com' => 'John Doe'])
->setTo(['infinity.community.work@gmail.com', 'other@domain.org' => 'A name'])
->setBody('Here is the message itself');
$mailer->send($message);
编辑: 成功使用 SwiftMailer 版本 5.4
我尝试通过 Swift-Mailer 发送电子邮件。根据文档,它应该像这样工作,但我既没有收到邮件也没有收到错误消息。
这里是 PHP Swift 文件的代码:
<?php
require_once '/composer/vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
->setUsername('*******@gmail.com')
->setPassword('password')
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['john@doe.com' => 'John Doe'])
->setTo(['infinity.community.work@gmail.com', 'other@domain.org' => 'A name'])
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
?>
这里是 composer.json:
{
"require": {
"swiftmailer/swiftmailer": "^6.0"
}
}
再次检查此语法并确保电子邮件或密码拼写正确:
$trp = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('*********@gmail.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($trp);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(['john@doe.com' => 'John Doe'])
->setTo(['infinity.community.work@gmail.com', 'other@domain.org' => 'A name'])
->setBody('Here is the message itself');
$mailer->send($message);
编辑: 成功使用 SwiftMailer 版本 5.4