为什么smtp服务器不';不再发送电子邮件了


Why the smtp server doesn't send emails anymore?

我遇到了一个非常奇怪的问题。我正在通过我的网站向其他收件人发送电子邮件。它在symfony,我对此非常陌生。这是我的代码

confg.yml

swiftmailer:
transport:  smtp
host:       smtp.gmail.com
encryption: ssl
username:   "myusername"
password:   "mypassword"
spool:     { type: memory }

这是我的表单功能

 public function formemailAction(Request $request)
 {
 // create a task and give it some dummy data for this example
        $newtask = new Task();
        $newtask->setsubject('add subject here');
        $newtask->setdescription("write your feed back here");
        $form = $this->createFormBuilder($newtask)
            ->add('subject', 'text')
            ->add('description', 'textarea')
            ->getForm();
 return $this->render('ServiceRequestBundle:Desk:shownotification.html.twig', array('form' => $form->createView(),
 ));
 }

在点击提交的表单中,我正在调用一个函数,在该函数中我将发送一封电子邮件

public function sendemailAction()
  {
      $messages = 'Swift_Message::newInstance()
          ->setSubject('again Notification Email')
          ->setFrom('myusername@gmail.com')
          ->setTo('username@gmail.com')
          ->setBody("we know that you dont know whats happening" )
      ;
      $this->get('mailer')->send($messages);
      return $this->render('ServiceRequestBundle:Desk:shownotification.html.twig');
  }

现在的问题是,它运行良好。但在发送了4到5封电子邮件后,它停止了工作,我的电子邮件也不再发送了。我的第一个猜测是,因为我一次又一次地调试我的应用程序,可能只是因为同一封电子邮件一次又一遍地发送。我遵循这个教程,那么我该如何解决这个问题,如果还有其他问题,请帮助我。

我检查了我的php错误日志,发现了这个

#0 [internal function]: Symfony'Component'HttpKernel'Debug'ErrorHandler->handle(2, 'SessionHandler:...', 'C:'xampp'htdocs...', 558, Array)
#1 C:'xampp'htdocs'jts'app'cache'dev'classes.php(558): SessionHandler->write('tatrpm617uplo16...', '_sf2_attributes...')
#2 [internal function]: Symfony'Component'HttpFoundation'Session'Storage'Proxy'SessionHandlerProxy->write('tatrpm617uplo16...', '_sf2_attributes...')
#3 [internal function]: session_write_close()
#4 {main}
  thrown in C:'xampp'htdocs'jts'app'cache'dev'classes.php on line 

我认为你需要一个中继,因为Gmail会认为它是垃圾邮件,可能会屏蔽你的地址。

您可以在CentOS上使用PostFix,也可以在windows中安装SMTP服务器

Centshttp://www.postfix.org/

WINDOWS:您可以下载SMTP服务器

http://www.microsoft.com/en-us/download/details.aspx?id=7887

并使用这些步骤进行配置

http://technet.microsoft.com/en-us/library/cc772058(WS.10(.aspx

如果是smtp传输,请检查php日志gmail上的auth。您是否尝试过tls而不是ssl

你可以尝试通过你自己的smtp服务器发送邮件:

首先,你应该检查是否有一个smtp服务器在你的服务器上运行:

netstat -tulpen | grep :25

这应该返回类似的内容:

tcp  0  0 0.0.0.0:25  0.0.0.0:* LISTEN  0  8485 1213/master

如果没有,您可以尝试启动服务器。如果是后缀,这是:

/etc/init.d/postfix start

如果你仍然没有收到邮件,请检查

/var/log/maillog

可能是邮件无法送达,你应该多看看邮件日志中的信息