我正在尝试从在localhost上运行的PHP脚本发送电子邮件。我正在使用gmail smtp服务器和swiftmailer。以下是代码:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('myusername')->setPassword('mypassword');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setSubject('Email from testing');
$message->setFrom(array(
$cleanEmail => $cleanName
));
$message->setTo(array('navjot.dcrust@gmail.com'));
$message->setBody($cleanMsg);
$result = $mailer->send($message);
if($result > 0) {
return $response->withRedirect($request->getUri()->getBasePath());
} else {
return $response->withRedirect($request->getUri()->getBasePath().'/contact');
}
它给了我以下错误:
Details
Type: Swift_TransportException
Code: 535
Message: Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials k11sm8212449wmb.18 - gsmtp "
File: C:\xampp\htdocs\practice\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php
Line: 383