drr47973 2014-10-15 06:47
浏览 60
已采纳

xampp localhost中的Swiftmailer不发送电子邮件(已经做了很多研究)

So I have spent days on trying to send e-mails using swiftmailer by php and I am using localhost xampp server v3.2.1, which the PHP version is 5.4.31 and my swiftmailer is I believe v5.3

Here is the PHP file :

require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
->setUsername('username@gmail.com')
->setPassword('password');

$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('username@gmail.com'))
->setTo(array('recipient@gmail.com'))
->setBody('Hello World')
;

$result = $mailer->send($message);
if (!$mailer->send($message,$failures)) {
  echo "Failures:";
  print_r($failures);
} else {
  echo "sent";
}

The page just returned blank and there are no e-mail sent or received.Please tell if there is anything I should configure before getting this to work or am I missing an important line of code or something.

Thank you in advance.

I keep trying and once I got an input in my error log which is :

[15-Oct-2014 16:33:49 Europe/Berlin] PHP Fatal error:  Uncaught exception 'Swift_TransportException' with 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 http://support.google.com/mail/bin/answer.py?answer=14257 fn2sm17247597pdb.75 - gsmtp

"' in C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php:386
Stack trace:
#0 C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(281): Swift_Transport_AbstractSmtpTransport->_assertResponseCode('535-5.7.8 Usern...', Array)
#1 C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\EsmtpTransport.php(245): Swift_Transport_AbstractSmtpTransport->executeCommand('RSET
', Array, Array)
#2 C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\Esmtp\Auth\XOAuth2Authenticator.php(56): Swift_Transport_EsmtpTransport->executeCommand('RSET
', Array)
#3 C:\xampp\htdocs\1\vendor\swiftmailer\swiftma in C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php on line 386
  • 写回答

3条回答 默认 最新

  • dqzlqfqeh845799833 2014-10-16 00:45
    关注

    It finally managed to send e-mails, what I had to do is change the security setting in my gmail account and disabled the security protection and now it sends e-mail perfectly

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样