php - Swift Mailer 不工作并且没有给出错误信息
问题描述
我尝试通过 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版成功合作
推荐阅读
- ruby - 如何从 Ruby 中的 BSON 文档中获取哈希?
- python - 将 2 个数据帧的 Pandas 析取附加到第一个数据帧
- python-3.x - 如何将迁移学习用于 LSTM?
- javascript - 数据表根据列值隐藏行
- mysql - 如何将 RapidMiner 中的关联规则存储到 MySQL 表中
- python - 一个函数的输出用作另一个函数的输入
- java - 通过递归反转单链表
- ios - bringSubviewToFront 不适用于下拉视图(UIView)
- json - nosql数据重复和性能?
- docker - docker run 的挂载选项(类型、源、目标)的含义是什么?