【发布时间】:2017-05-03 14:23:19
【问题描述】:
我有以下代码使用Swift mailer 通过 PHP 发送邮件
<?php
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465, 'ssl')
->setUsername('my.email@mydomain.com')
->setPassword('emailpassword');
$message = Swift_Message::newInstance()
->setSubject("This is test subject")
->setFrom(array("sender.email@gmail.com"))
->setTo(array("recipient.email@gmail.com"))
->setBody("This is test mail body","text/html");
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
这很好用,收件人会收到一封电子邮件。但是,如果我像这样将传输中的用户名和密码更改为 gmail 的用户名和密码 -
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465, 'ssl')
->setUsername('sender.email@gmail.com') //this is the change, using gmail
->setPassword('senderpassword'); //this is the change
那么这不起作用。
谁能告诉我哪里做错了?我缺少什么配置?
附:我也检查了垃圾邮件文件夹
【问题讨论】:
标签: php swiftmailer