我在使用 swiftmailer 时遇到了一些问题。它一直在我身上崩溃,但如果我取出 ->sentTo 它不会出错,但我也无法收到电子邮件。
我对自己做错了什么感到困惑。
require_once 'lib/swift_required.php';
// Using smtp
//$transport = Swift_SmtpTransport::newInstance('my_smtp_host.com', 25)
//Using Gmail
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('***') // or your gmail username
->setPassword('***'); // or your gmail password
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance($subject)
->setFrom(array($email => $name))
->setTo(array('John.Doe@gmail.com' => 'John Doe'))
->setBody($content, 'text/html');
$message->attach(
Swift_Attachment::fromPath($_FILES['userfile']['name'])->setFilename($pic['tmp_name'])
);
// Send the message
$result = $mailer->send($message);
?>
致命错误:
Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "...." using 2 possible authenticators' in ../lib/classes/Swift/Transport/Esmtp/AuthHandler.php:184
Stack trace:
0 ../lib/classes/Swift/Transport/Esmtp/EsmtpTransport.php(312): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
1 ../lib/classes/Swift/Transport/AbstractSmtpTransport.php(120): Swift_Transport_EsmtpTransport->_doHeloCommand()
2 ../lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()
3 upload.php(73): Swift_Mailer->send(Object(Swift_Message))
4 {main} thrown in lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 184